Matrices – Practice Questions and FRQ

Matrices

1 / 2

Given the following code snippet, what is the result of array[2][1] after execution?

int[][] array = new int[3][3];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = i * j;
}
}

2 / 2

What will the following method output when called with a 2D array?

public static void printDiagonal(int[][] matrix) {
for (int i = 0; i < matrix.length; i++) {
System.out.print(matrix[i][i] + " ");
}
}
public static void main(String[] args) {
int[][] array = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printDiagonal(array);
}

Your score is

The average score is 50%

0%

Scroll to Top