Question
Refer to the following method rotate that takes a two-dimensional array a and returns a two-dimensional array b made by rotation a by 90 degrees
Refer to the following method rotate that takes a two-dimensional array a and returns a two-dimensional array b made by rotation a by 90 degrees counterclockwise.
If a holds:
1 2 3
4 5 6
b = rotate(a) will hold:
4 1
5 2
6 3
public int[][] rotate(int[][]a){
int rows = a[0].length;
int cols = a.length;
int[][] b = new int [rows][cols];
for (int r=0; r < rows; r++)
for (int c=0; c < cols; c++)
b[r][c] = <MISSING EXPRESSION>;
return b;
}
Which of the following should replace <MISSING EXPRESSION>?
A) a[c][rows - 1 - r]
B) a[cols - 1 - c][rows -1 -r]
C) a[rows - 1 - r][cols - 1- c]
D) a[cols - 1 - c][r]
E) a[c][r]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started