誰能幫我解釋一下這個for循環
public class HelloWorld{
public static void main(String[] args){
? ? int num = 999;
? ? int count = 0;
? ? for(int i = 1;i<=num;i = i*10){
? ? ? ? count++;
? ? }
? ? System.out.println("它是個"+count+"位的數!");
}
}
public class HelloWorld{
public static void main(String[] args){
? ? int num = 999;
? ? int count = 0;
? ? for(int i = 1;i<=num;i = i*10){
? ? ? ? count++;
? ? }
? ? System.out.println("它是個"+count+"位的數!");
}
}
2022-01-25
舉報
2022-01-25
這不就是用最小的二位數,三位數去比較嗎,只要i大于了,比如成了1000,1000大于這個數,上一次是100小于這個數,說明是三位數