- public class MathDemo {
- public long sums(){
- long sum = 0;//所有乘积的和
- long product = 0;//单个乘积
-
- for (int i = 0; i <= 100; i++) {
- sum+=product;//总数加等于单个乘积
- product = 0;//成绩被总数收纳后归零
- for (int j = i; j <=100 ; j++) {
- product += j * i;
- }
- System.out.println(product);//可以看到每个加数的所有乘积
- }
- return sum;
- }
-
- public static void main(String[] args) {
- MathDemo md = new MathDemo();
- System.out.println(md.sums());//总数是12910425
- }
- }
复制代码 |