1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
package 控制语句;
public class TestWhile { public static void main(String[] args) { int i = 1; int sum = 0; while(i <= 100) { sum += i; i++; } System.out.println(sum);
i = 0; sum = 0; do { sum += i; i++; }while(i <= 100); System.out.println(sum); } }
|