import java.util.Scanner;
public class Test {
public static void main(String[] args) {
while (true) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入一个正整数:");
int count = 0;
int n = sc.nextInt();
if (n == 0) {
count = 1;
} else {
while (n != 0) {
count++;
n = n / 10;
}
}
System.out.println(count);
}
}
}
效果展示: