题解 | #二维数组求和#
//接触JAVA后第一次碰到二维数组,还是挺有意思的,学到了那么一丢丢操作诶~~~
public class Main {
public static void main(String[] args) {
int[][] arr = {{11,33,55},{22,44,66,88},{131,214,315,146},{928,827,726,625},{424,525}};
int sum=add(arr);
System.out.println(sum);
}
public static int add(int[][] arr) {//取有多少行
int sum=0;
//write your code here......
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){//取每一行有多少列
sum += arr[i][j];
}
}
return sum;
}
}