APCSA Question of the Week: 2D Arrays

Apr 28, 2025

APCSA Question of the Week: 2D Arrays

This week's question is from Unit 8: 2D Arrays. There will be 3-4 questions on the exam about 2D Arrays.

For this week's question, only 24% of students get it correct on the first try.

Try it for yourself on Passionfruit before scrolling to see the answer and explanation below!

https://app.passionfruitlearning.com/ap-computer-science-a/multiple-choice/2d-arrays-ijZyXvy


Explanation and Solution

Here's the step-by-step thought process I use whenever I see a nested-loop problem like the question above:

When analyzing any nested loop, zero in on the following key points 💡
  1. Loop order
    Which loop is outer, which is inner?
    In this code snippet, columns are the outer loop; rows are the inner loop.

  2. Initial value – comparison operator – update
    Where does each loop start, how does it stop, and which way does it move?

    for (int col = grid[0].length - 1; col >= 0; col--) // right → left
        for (int row = 0; row < grid.length; row++) // top → bottom


  3. The body of the loop
    Exactly what is printed or changed each pass?
    System.out.print(grid[row][col] + " "); This just prints the item at [row][col].

  4. What the question is asking for
    In this case: “Which answer choice matches the printed output?”


The Quick Approach 🚀

Instead of mentally juggling indices, try a mini trace with real values by writing out the grid with row/column labels. Here's the starting 2D Array:

row\col

0

1

2

0

X

Y

Z

1

P

Q

R

2

L

M

N

Now we follow the loops:

  1. col = 2 (right-most)
    rows 0→2 → Z R N
    (print space after each, newline after the column finishes)

  2. col = 1 → Y Q M

  3. col = 0 → X P L

We see the full output:



The Pattern 🧩

Notice what happened:

  • The outer loop counts columns backward ⇒ every line is a different column from right to left.

  • The inner loop counts rows forward ⇒ letters in each line go top → bottom.

That combination flips the grid horizontally and prints it column by column.

Option E is the only perfect fit.

Quick Tips for Similar Questions 💡
  1. Label a tiny table if the 2D array is small (3×3 here).

  2. Run the first two iterations—patterns jump out fast.

  3. Track outer vs. inner loops separately.

  4. For 2-D arrays, ask: “Am I reading rows first or columns first?”

As always, if you have any additional questions, feel free to ask Passionfruit’s AI Tutor or email us at jason@passionfruitlearning.com.

See you next time! 🍍