✏️ Explanatory Question
Declare a 2D array of integers in Java with 3 rows and 4 columns. Initialize the array with the following values:
1 2 3 4 5 6 7 8 9 10 11 12
Declare a 2D array of integers in Java with 3 rows and 4 columns. Initialize the array with the following values:
1 2 3 4 5 6 7 8 9 10 11 12
Write a Java program to print all the elements of the array.:
public class Main {
public static void main(String[] args) {
int[][] array = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}
}