6789 反转 9876

    1. 获取思维整数的个位、十位、百位、千位
    2. 个位1000+十位100+百位*10+千位
    1. public static void main(String[] args) {
    2. System.out.println("请输入一个四位整数");
    3. Scanner scanner = new Scanner(System.in);
    4. // 1.获取思维整数的个位、十位、百位、千位
    5. int number = scanner.nextInt();
    6. System.out.println("读取到您输入的整数" + number);
    7. int unit = number % 10;
    8. int ten = number / 10 % 10;
    9. int hundred = number / 100 % 10;
    10. int thousand = number / 1000 % 10;
    11. System.out.printf("个位:%d,十位:%d,百位:%d,千位:%d", unit, ten, hundred, thousand);
    12. // 2.个位*1000+十位*100+百位*10+千位
    13. int result = unit * 1000 + ten * 100 + hundred * 10 + thousand;
    14. System.out.println("\n result = "+ result);
    15. }