|
|
#2
hwoarangzk2008-07-30 13:03
|
将1到20的整数依次加到sum中,知道sum大于等于100.
我的程序是这样的:
public class TestBreak {
public static void main(String[] args) {
int sum = 0;
while (sum < 100) {
for (int i = 0; i <= 20; i++)
sum += i;
}
System.out.println("The sum is " + sum);
}
}
可是运行后的结果是:The sum is 210.
这是怎么回事啊?
麻烦各位高手不吝赐教!