使用到循环结构中的while循环
public class demo {public static void main(String[] args) {//统计字符的个数//程序要读入一个正整数,然后输出这个整数的位数?//输入:352,输出:3.System.out.println("请输入三位数:");Scanner in =new Scanner(System.in);int number=in.nextInt();int count=0;while(number>0){number=number/10;count=count+1;}System.out.println("输出:"+ count);}
}
运行代码截图