本文由搞代码网为大家展示了《java打印1-100所有偶数的和》的代码案例,请各位coder不吝赐教,也欢迎coder点赞收藏转发,感谢
public class age13 { public static void main(String args[]) { // 定义一个变量 int i = 1; // 定义一个存储结果的变量 int total = 0; while (i <= 100) { if (i % 2 == 0) { total += i; } i++; } System.out.println("最终结果=" + total); } }