美文网首页
Java算法——二维数组的遍历,求和

Java算法——二维数组的遍历,求和

作者: 白驹过隙_a | 来源:发表于2019-01-07 17:44 被阅读0次
    public class Array2BianLi {
     
        public static void main(String[] args) {
     
            int[][] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
     
            int sum = 0;
            System.out.println("遍历二维数组:");
     
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr[i].length; j++) {
                    System.out.print(arr[i][j] + " ");
                    sum += arr[i][j];
                }
                System.out.println();
            }
            System.out.println("所有元素总和为:" + sum);
        }
     
    }
    

    相关文章

      网友评论

          本文标题:Java算法——二维数组的遍历,求和

          本文链接:https://www.haomeiwen.com/subject/jyqprqtx.html