为什么输出是15而不是21
package tiaojian;
public class Forbreak1 {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum = sum + i;
if (sum > 20) {
break;
}
System.out.println("当前的累加值为:" + sum);
}
}
}
package tiaojian;
public class Forbreak1 {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum = sum + i;
if (sum > 20) {
break;
}
System.out.println("当前的累加值为:" + sum);
}
}
}
2018-08-21
举报