2D Array Row Right Shift
Consider the following method.
public static void shiftRight(int[][] arr, int row) {
int last = arr[row][arr[row].length - 1];
for (int col = arr[row].length - 1; col > 0; col--) {
arr[row][col] = arr[row][col - 1];
}
arr[row][0] = last;
}
Assume that a 2D array arr is initialized so that arr[2] contains {10, 20, 30, 40}. What are the contents of arr[2] after the method call shiftRight(arr, 2) is executed?
A
{40, 10, 20, 30}
B
{10, 40, 30, 20}
C
{20, 30, 40, 10}
D
{30, 40, 10, 20}
Question Leaderboard
Not enough data yet to show leaderboard.
