Day 2: Arrays + 2D Arrays | AP CSA 7-Day Cram Kit

DAY 2  |  Arrays + 2D Arrays

Unit 4  |  30–40% of exam  |  FRQ 4 is always a 2D array problem

Your Plan for Today

STEP 1Review Concepts (15 min)

Read the concept summary below.

apcsexamprep.com/pages/ap-csa-unit-4-data-collections-study-guide

Focus: 1D Arrays, 2D Arrays, row/column traversal.

STEP 2MCQ Practice (25 min)

Use the Test Builder. Set filter: Unit 4 → Arrays and 2D Arrays.

apcsexamprep.com/pages/ap-csa-test-builder

Do 10 questions. 2 minutes max per question.

-> Score 8-10: move to Step 3.

-> Score 5-7: reread the 2D array traversal section, then do Step 3.

-> Score 0-4: reread the full arrays section. Redo 10 questions before Step 3.

STEP 3FRQ Practice (35 min)

Write the full solution on paper BEFORE checking the answer.

Use: 2024 AP CSA Free Response Question 4 (2D Array problem)

apcsexamprep.com/pages/ap-csa-2024-frq-4-solution

FRQ Task: 2024 AP CSA Free Response Question 4

Write your full answer on paper or in Bluebook before checking the solution.

Solution: apcsexamprep.com/pages/ap-csa-2024-frq-4-solution

Your Score What to Do
0–3 pts Stop and reread 2D array traversal. Then do 2023 FRQ 4 as extra practice.
4–6 pts Review what you missed, then move to Day 3.
7–9 pts Excellent. Move to Day 3.

Concept Review

1D Arrays
  • int[] arr = new int[5]; — creates array of 5 zeros (fixed size forever)
  • int[] arr = {1, 2, 3}; — declares and fills at the same time
  • arr[i] — access element at index i
  • arr.length — number of elements (NOT a method — no parentheses)
  • Valid indices: 0 to arr.length - 1. Accessing outside this range crashes the program.
  • Arrays are FIXED SIZE — you cannot add or remove elements after creation
2D Arrays — Row First, Then Column
  • int[][] grid = new int[3][4]; — 3 rows, 4 columns
  • grid[r][c] — row index FIRST, column index SECOND
  • grid.length — number of ROWS  |  grid[0].length — number of COLUMNS
  • Outer loop = rows (grid.length), inner loop = columns (grid[r].length)
  • Main diagonal: grid[i][i] where i goes from 0 to grid.length - 1
// Standard 2D array traversal
for (int r = 0; r < grid.length; r++)
{
   for (int c = 0; c < grid[r].length; c++)
   {
      System.out.print(grid[r][c] + " ");
   }
   System.out.println();
}

Practice Questions

Q6.  [SPOT THE ERROR]
The method below should shift all array elements one position to the left, placing the first element at the end. What is wrong?
public static void shiftLeft(int[] values)
{
   for (int i = 0; i < values.length - 1; i++)
   {
      values[i] = values[i + 1];
   }
   values[values.length - 1] = values[0];   // BUG
}
  • (A) The loop should start at index 1, not index 0
  • (B) values[0] is overwritten before it is saved, so its original value is permanently lost
  • (C) The condition should be i <= values.length - 1
  • (D) There is no bug
▶ REVEAL ANSWER

Answer: B

The first line of the loop overwrites values[0] with values[1], destroying the original first element. Then the last assignment copies the already-overwritten value, not the original. Fix: save values[0] before the loop, then assign it to the last position after.

Q7.  [I/II/III]
Which of the following statements about arrays in Java are TRUE?
I. Passing an array to a method and modifying its elements changes the original array.
II. arr.length is a method call that requires parentheses.
III. An int array is initialized to all zeros by default when created with new.
  • (A) I only
  • (B) I and III only
  • (C) II and III only
  • (D) I, II, and III
▶ REVEAL ANSWER

Answer: B

I is TRUE -- arrays are objects; the method receives a reference to the same array. II is FALSE -- length is a field, not a method. No parentheses. III is TRUE -- int arrays default to 0.

Q8.  [TRACE]
What is the value of total after this code runs on a 3x3 grid containing 1 through 9 in row-major order?
int total = 0;
for (int r = 0; r < grid.length; r++)
{
   for (int c = 0; c < r; c++)
   {
      total += grid[r][c];
   }
}
  • (A) 45
  • (B) 19
  • (C) 15
  • (D) 12
▶ REVEAL ANSWER

Answer: B

The inner loop runs while c < r (below the diagonal only). Row 0: nothing. Row 1: grid[1][0] = 4. Row 2: grid[2][0]=7, grid[2][1]=8. Total = 4+7+8 = 19.

Q9.  [ALWAYS/NEVER]
Which of the following will ALWAYS cause an ArrayIndexOutOfBoundsException, regardless of the length of arr (assuming arr.length >= 1)?
  • (A) arr[arr.length - 1]
  • (B) arr[arr.length]
  • (C) arr[0]
  • (D) arr[arr.length / 2]
▶ REVEAL ANSWER

Answer: B

Valid indices are 0 through arr.length - 1. arr[arr.length] is always one beyond the last valid index.

Q10.  [SPOT THE ERROR]
This method should return the largest value in a 2D int array. What is the bug?
public static int findMax(int[][] grid)
{
   int max = 0;   // BUG: should be grid[0][0]
   for (int r = 0; r < grid.length; r++)
   {
      for (int c = 0; c < grid[r].length; c++)
      {
         if (grid[r][c] > max)
         {
            max = grid[r][c];
         }
      }
   }
   return max;
}
  • (A) The method should use a while loop instead of nested for loops
  • (B) max is initialized to 0, which fails if all elements are negative
  • (C) The outer loop should go up to grid[0].length instead of grid.length
  • (D) grid[r][c] should be grid[c][r]
▶ REVEAL ANSWER

Answer: B

If every value in the grid is negative, max stays at 0 and the method returns 0 -- wrong. Fix: initialize max = grid[0][0] before the loops.

Answer Key (for printing)

Q6: B    Q7: B    Q8: B    Q9: B    Q10: B

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]