1int[][] multiples = new int[4][2]; // 2D integer array with 4 rows
2 and 2 columns
3String[][] cities = new String[3][3]; // 2D String array with 3 rows
4 and 3 columns
1class MultidimensionalArray {
2 public static void main(String[] args) {
3
4 int[][] a = {
5 {1, -2, 3},
6 {-4, -5, 6, 9},
7 {7},
8 };
9
10 for (int i = 0; i < a.length; ++i) {
11 for(int j = 0; j < a[i].length; ++j) {
12 System.out.println(a[i][j]);
13 }
14 }
15 }
16}
1class MultidimensionalArray {
2 public static void main(String[] args) {
3
4 // create a 2d array
5 int[][] a = {
6 {1, -2, 3},
7 {-4, -5, 6, 9},
8 {7},
9 };
10
11 // first for...each loop access the individual array
12 // inside the 2d array
13 for (int[] innerArray: a) {
14 // second for...each loop access each element inside the row
15 for(int data: innerArray) {
16 System.out.println(data);
17 }
18 }
19 }
20}