public class Demosum {
public static void main(String[] args) {
int sum = 0;
int i = 0;
do {
sum = i + sum;
i++;
} while (i % 2 == 0 && i < 51);
System.out.println("求和是:" + sum);
}
do里面i++之后,i=1, while (i % 2 == 0 && i < 51)中i%2=1,条件不满足,退出循环,sum=0
sum+=num; 希望你能懂!