二维数组

一. 二维数组遍历

package test_1;

  public class test_7 {
    public static void main(String[] args) {
      int[][] arr = {{1,2,3},{5,6},{12,13,14}};

      for(int i=0; i< arr.length ; i++) {
        for(int j=0; j < arr[i].length ; j++){
          System.out.print(arr[i][j] +" ");
          }
        System.out.println("");
      }
  }

}

二. 二维数组求和

package test_1;

  public class test_8 {

    public static void main(String[] args) {
      int[][] arr = {{33,44,55},{77,55,33},{33,55,77},{99,88,77}};
      int sum =0;
      for(int i=0; i< arr.length ; i++) {
        for(int j=0; j < arr[i].length ; j++){
          sum =sum +arr[i][j];
          }
      }System.out.println(sum);
}

}

posted @ 2020-05-10 19:40  雨曼晴川  阅读(86)  评论(0)    收藏  举报