- class Demo {
- public static void main(String[] args) {
-
- int[][] arr = {{1,3,5,8,},{13,4,7,3},{23,56,67,46}};
- int sum=0;
- for(int x=0;x<arr.length;x++)
- {
- for(int y=0;y<arr[x].length;y++)//修改此处 二维数组遍历的时候为arr[x].length
- {
- sum = sum+arr[x][y];
- }
- }
-
- System.out.println("sum="+sum);
- }
- }
复制代码 |