為什么會輸出21?循環(huán)條件不是只到20為止嗎?
package tiaojian;
public class For {
public static void main (String []args){
int i=0;
while (i<=20){
i++;
System.out.println(i);
}
}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
}
package tiaojian;
public class For {
public static void main (String []args){
int i=0;
while (i<=20){
i++;
System.out.println(i);
}
}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
}
2018-09-05
舉報
2018-09-08
i為20的時候還是會自增一次的。改為i<20,即19的時候輸出就是20了
2018-09-05
while(i<=20)改為while(i<20)