public class plus{
public static void main(String args[]) {
int sum = 0;
int n = 100;
do {
n--;
}
while (n > 0);//当n==1时,还要去执行n--,之后,n==0,不满足条件,才执行while()后面的代码块。此时n==0了,所以结果是0
{
sum += n;
}
System.out.println("the sum of the first 100 natural number is" + sum);
}
} |