使用eclipse :输入一个0~99999之间的任意数,判断输入的数是几位数?

2024-12-02 02:57:35
推荐回答(1个)
回答1:

import java.util.*;
public class Tmp {
public static void main(String args[]) {
System.out.println("输入一个0-9999的数");
Scanner imput = new Scanner(System.in);
Integer n = imput.nextInt();
String s = n.toString();
int length = s.length();
switch(length) {
case 1:
System.out.println("一位数");
break;
case 2:
System.out.println("两位数");
break;
case 3:
System.out.println("三位数");
break;
case 4:
System.out.println("四位数");
break;
default:
System.out.println("输入有误");
}

}
}