java nested arrays code example
Example 1: two dimensional array in java example program
class MultidimensionalArray {
public static void main(String[] args) {
int[][] a = {
{1, -2, 3},
{-4, -5, 6, 9},
{7},
};
for (int i = 0; i < a.length; ++i) {
for(int j = 0; j < a[i].length; ++j) {
System.out.println(a[i][j]);
}
}
}
}
Example 2: 2d arrays | java
int[][] arr = new int[row][column];
Example 3: 2d array java
int[][]arr= new int [filas][columnas];
arr.length=filas;
int[][] a = {
{1, 2, 3},
{4, 5, 6, 9},
{7},
};
System.out.println("Length of row 1: " + a[0].length);
System.out.println("Length of row 2: " + a[1].length);
System.out.println("Length of row 3: " + a[2].length);
}
Example 4: two dimensional array in java example program
class MultidimensionalArray {
public static void main(String[] args) {
int[][] a = {
{1, -2, 3},
{-4, -5, 6, 9},
{7},
};
for (int[] innerArray: a) {
for(int data: innerArray) {
System.out.println(data);
}
}
}
}
Example 5: two dimensional array in java example program
int[][] a = new int[3][4];