二维数组所有元素求和输出

 1 public class zuoye2 {
 2 
 3     public static void main(String[] args) {
 4 
 5    int arr [][]={{1,6,56,45,},{6,8,4,6,},{6,9,5,9}};
 6    int sum=0;
 7    System.out.println("输出二维数组遍历");
 8    
 9   
10    for(int[]x:arr)
11    {
12        for(int y:x)
13        {
14            System.out.print(y+", ");
15            sum+=y;
16        }
17        System.out.println();
18    }
19    
20    System.out.println("所有元素的和为"+sum);
21 
22 
23     }
24 
25 }

posted on 2016-01-11 00:45  宁静致远-zw  阅读(1307)  评论(0编辑  收藏  举报