?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

2-D Arrays

APCSA-UW68BE

The following method takes a two-dimensional array a and returns a two-dimensional array b made by rotating a by 90° counterclockwise.

public int[][] rotate(int[][]a)
 {
 int rows = **EXPRESSION 1**;
 int cols = **EXPRESSION 2**;
 int[][] b = **EXPRESSION 3**;

 for (int r = 0; r < rows; r++)

       for (int c = 0; c < cols; c++)

            b[r][c] = **EXPRESSION 4**;

 return b;
 }

For example, if a holds
1 2 3
4 5 6

b = rotate(a) will hold

3 6
2 5
1 4

Which of the following should replace EXPRESSION 1, EXPRESSION 2, and EXPRESSION 3?

A

EXPRESSION 1 = a[0].length
EXPRESSION 2 = a.length
EXPRESSION 3 = new int[]

B

EXPRESSION 1 = a.cols()
EXPRESSION 2 = a.rows()
EXPRESSION 3 = new int(rows, cols)

C

EXPRESSION 1 = a[0].length
EXPRESSION 2 = a.length
EXPRESSION 3 = new int[rows][cols]

D

EXPRESSION 1 = a.cols
EXPRESSION 2 = a.rows
EXPRESSION 3 = new int(rows, cols)

E

EXPRESSION 1 = a.cols
EXPRESSION 2 = a.rows
EXPRESSION 3 = new int[]