* 计算∑1+∑2+∑3+……+∑100 * =1 +(1+2)+(1+2+3)+(...)+(1+2+3+4+5+…+100)
/** * 计算∑1+∑2+∑3+……+∑100 * =1 +(1+2)+(1+2+3)+(...)+(1+2+3+4+5+…+100) */ package jieduan1.No4; public class Sum100 { public static void main(String[] args) { int b = 0; int sum =0; for (int i = 1; i <= 100; i++) { for (int a = 1; a <= i; a++) { b += a; a++; } sum+=b; } System.out.println("该式子的和为" + sum); } }
运行结果如下: