6789 反转 9876
- 获取思维整数的个位、十位、百位、千位
- 个位1000+十位100+百位*10+千位
public static void main(String[] args) {System.out.println("请输入一个四位整数");Scanner scanner = new Scanner(System.in);// 1.获取思维整数的个位、十位、百位、千位int number = scanner.nextInt();System.out.println("读取到您输入的整数" + number);int unit = number % 10;int ten = number / 10 % 10;int hundred = number / 100 % 10;int thousand = number / 1000 % 10;System.out.printf("个位:%d,十位:%d,百位:%d,千位:%d", unit, ten, hundred, thousand);// 2.个位*1000+十位*100+百位*10+千位int result = unit * 1000 + ten * 100 + hundred * 10 + thousand;System.out.println("\n result = "+ result);}
