Example 2: multidimensional array

This is a Java program that demonstrates the use of a multidimensional array.

The program starts by defining a two-dimensional integer array called “myArray”, with the values {{0, 1}, {0, 1, 2, 3}, {0, 1, 2, 3, 4}}.

The code then uses two for loops, one nested inside the other, to loop through each element in the array. The first loop uses the “myArray.length” attribute to loop through each row, and the second loop uses the “myArray[i].length” attribute to loop through each column in the current row.

For each element in the array, the program prints its value using the “System.out.print” method. After each row is printed, a newline character is added using the “System.out.println” method to separate the rows.

import java.util.Arrays;

public class MultidimensionalArrayExample {
	public static void main(String[] args) {
		int[][] myArray = { { 0, 1 }, { 0, 1, 2, 3 }, { 0, 1, 2, 3, 4 } };

		for (int i = 0; i < myArray.length; i++) {
			for (int j = 0; j < myArray[i].length; j++) {
				System.out.print(myArray[i][j]);
			}
			System.out.println();
		}
	}
}
Output
01
0123
01234