leetcod算法1
回文�?
/*
leetcode回文�?:
输入一个整数x,如果是一个回文整数,打印true,否则,返回false
*/
import java.util.Scanner;
public class Palindrome_number {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int tmp = x;//记录最开始的x�?
int num = 0;
while(x!=0){
int ge = x % 10;//获取个位�?
x = x / 10;
num = num * 10 + ge;
}
System.out.println(num);
System.out.println(num == tmp);
}
}
求商和余�?
/*
给定两个整数,被除数和除数(都是正数,切不超出int的范围)
将两数相除,要求不适用乘法,除法和%运算符。得到商和余�?
*/
import java.util.Scanner;
public class itheima_p48 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();//输入被除�?
int b = in.nextInt();//输入除数
int num = 0;
while(a >= b){
a=a-b;
num++;
}
System.out.println("余数�?"+a);//余数
System.out.println("商为"+num);//�?
}
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 doathuwant!