public class helloworld {
public static void main(String[] args){
int num = 999;
int count = 0;
if (num >= 0 && num<=999999999){
while(num != 0){
count++;
num/=10;// a/=b等同于a=a/b
}
System.out.println("他是个"+count+"位的数!");
}else{
System.out.println("输入有误!");
}
}
}
count是位数。count++是count=count+1。当num不等于0时,count至少是1.所以先执行count++,然后再判断num是否是高位数。
count++ --> 即count自加,相当于:count=count+1;
count++是count加1,代码类似于count=count+1;