回文数

/*
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);//商
    }
}