• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

数组求和

开发技术 开发技术 2周前 (04-29) 6次浏览
package com.itheima.demo01.arr;

public class StudentSum {
    public static void main(String[] args) {
        int[]arr={120,130,110,125,128,164};
        /*int totalWeight=0;
        for (int i = 0; i < arr.length; i++) {
            int weight=arr[i];
            totalWeight+=weight;
        }
        System.out.println(totalWeight);*/
        int totalWeight=0;
        for (int i = 0; i < arr.length; i++) {
           int weight=arr[i];
           totalWeight+=weight;

        }
        System.out.println(totalWeight);
    }

}


程序员灯塔
转载请注明原文链接:数组求和
喜欢 (0)