class ZuoYe {
public static void main(String[] args) {
TongJi_1 t = new TongJi_1();
t.tongJi();
//int t = tongJi(arr);
System.out.println("t ="+t); //t =TongJi_1@1e4d6ef!
//int[][] arr1 = {{22,66,44},{77,33,88},{25,45,65},{11,66,99}};
//int x = tongJi(arr);
//System.out.println(x);
}
}
class TongJi_1 {
int[][] arr1 = {{22,66,44},{77,33,88},{25,45,65},{11,66,99}};
int tongJi() {
//int[][] arr1 = {{22,66,44},{77,33,88},{25,45,65},{11,66,99}};
int sum = 0; //定义一个变量记录住每次遍历出的值 对其进行累加
for (int i = 0; i < arr1.length; i++) { //获取每一个一维数组
for (int j = 0;j < arr1[i].length ; j++) { //获取每一个一维数组的元素
sum += arr1[i][j];
}
}
return sum;
}
}
|
|