package com.cc.java;
/*
*/
public class TestGetSum {
public static void main(String[] args) {
int[][] m = new int[][]{{3,8,2},{2,7},{9,0,1,6}};
int sum = 0 ;
for(int i =0;i<m.length;i++){
for(int j =0;j<m[i].length;j++){
System.out.print(m[i][j]+"\t");
sum += m[i][j];
}
System.out.println();
}
System.out.println("总和为:"+sum);
}
}
/*
* 练习2:获取arr数组中所有元素的和。使用for的嵌套循环即可。
j=0 | j=1 | j=2 | j=3 | |
i=0 | 3 | 8 | 2 | |
i=1 | 2 | 7 | ||
i=2 | 9 | 0 | 1 | 6 |
public class TestGetSum {
public static void main(String[] args) {
int[][] m = new int[][]{{3,8,2},{2,7},{9,0,1,6}};
int sum = 0 ;
for(int i =0;i<m.length;i++){
for(int j =0;j<m[i].length;j++){
System.out.print(m[i][j]+"\t");
sum += m[i][j];
}
System.out.println();
}
System.out.println("总和为:"+sum);
}
}