為什么int count = 0;放到for()里面賦值就會報錯,for之前賦值就沒問題
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
for(;num!=0;count++){
? ? num/=10;
}
System.out.println("它是個"+count+"位的數!");
}
}
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
for(;num!=0;count++){
? ? num/=10;
}
System.out.println("它是個"+count+"位的數!");
}
}
2019-08-19
舉報
2019-08-19
因為count如果放在for循環里面定義的話 就是內部定義,count只能在for循環里面使用 ,System.out.println("它是個"+count+"位的數!");中的count就找不到定義了
2019-08-19
System.out.println("它是個"+count+"位的數!");里面還有個count
2019-08-19
在for循環里面定義就只能在for循環里面使用了