Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Data Collections
Start Practice TestPractice Test
About Exam
easy Solved by 1 students

2D Array Row Right Shift

Mark
< Prev
Next >

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}

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|