public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
for(;num>=1;num/10)
count++;
System.out.println("它是个"+count+"位的数!");
}
}
如果用for循环如下:
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
for(;;){
count++;
num = num / 10;
if(num == 0)
break;
}
System.out.println("它是个"+count+"位的数!");
}
}
只需要做个小小的改动,在/后面加个=号即可