class TestWhile01 { public static void main(String[] args) { //输出5行HelloWorld! // 初始化 int i = 0; //条件判断 while(i < 5){ //循环体 System.out.println("Hello World!"); //迭代 i++; } //遍历1-100的偶数,并计算所有偶数的和、偶数的个数(累加的思想) int sum = 0; int count = 0; int k = 1; //条件判断 while(k <= 100){ //循环体 if( k % 2 ==0 ){ count++; sum+=k; } //迭代 k++; } System.out.println("和"+sum); System.out.println("个"+count); } }