public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
int b=1;
for (int i=1;i<10;i++){
b*=10;
if (num<b){
System.out.println("它是个"+i+"位的数!");
break;
}
}
}
}
public class Imooc4 {
public static void main(String[] args) {
int num = 999;
int count = 0;
if (num >= 0 && num <= 99999) {
while (num != 0) {
count++;
num /= 10;
}
System.out.println("它是个" + count + "位的数!");
}
}
}
//不需要定义那么多变量
你都定义num,count,还去定义b和i干嘛?