1 //遍历100以内的偶数,获取所有偶数的和,输出偶数的个数 2 3 int i =1; 4 int sum = 0; 5 int count = 0; 6 for(i = 1;i<=100;i++) 7 { 8 if(i%2==0) 9 { 10 System.out.println(i); 11 sum += i; 12 count++; 13 } 14 15 16 } 17 18 System.out.println("总和为:"+sum); 19 System.out.println("个数为:"+count); 20 21