@57、:键盘输入一个不多于5位的正整数,若输入的整数不合法,则提示“输入的数字不合法!”。
//并完成以下要求:1.求该整数是几位数;2.将输入的内容反转后在控制台打印输出,演示格式如下:
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个不多余5位的正整数");
int number = sc.nextInt();
if(number>=0&&number<100000){
int count = 1;
int ge = number%10;
int shi = number/10%10;
int bai = number/100%10;
int qian = number/1000%10;
int wan = number/10000%10;
//int d = number/10;
while(number/10!=0){
number/=10;
count++;
}
System.out.println("这是一个"+count+"位数");
switch(count){
case 5:
int number1 = ge*10000+shi*1000+bai*100+qian*10+wan;
System.out.println(number1);
break;
case 4:
int number2 = ge*1000+shi*100+bai*10+qian;
System.out.println(number2);
break;
case 3:
int number3 = ge*100+shi*10+bai;
System.out.println(number3);
break;
case 2:
int number4 = ge*10+shi;
System.out.println(number4);
break;
case 1:
int number5 = ge;
System.out.println(number5);
break;
}
}else{
System.out.println("输入的数字不合法!");
}
}