1. What is the purpose of the following java code?
int[][] arr = new int[3][4];
Ans. It creates a two- dimensional array with 3 rows and 4 columns.
2. What is the output of the following Java code?
int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
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();
}
Ans. 1 2 3 4 5 6 7 8 9.
3. What is the output of the following Java code?
int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int sum = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
sum += arr[i][j];
}
}
System.out.println(sum);
Ans. 45.
