java二维数组应用示例

2019年2月14日19:40:33 发表评论 950 views
/**
 * Created by xabcd on 2019/2/14.
 */
public class Java_2arrays {
    public static void main(String args[]) {
        int i, j, sum = 0;
        int num[][] = {{30, 35, 26, 32}, {33, 34, 30, 29}};
        for (i = 0; i < num.length; i++) {
            System.out.print("第" + (i + 1) + "个人的成绩为");
            for (j = 0; j < num[i].length; j++) {
                System.out.print(num[i][j] + "  ");
                sum += num[i][j];
            }
            System.out.println();
        }
        System.out.println("\n总成绩是:" + sum + "分!");
    }

}



结果:

第1个人的成绩为30 35 26 32
第2个人的成绩为33 34 30 29

总成绩是:249分!



发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: