For each question: read the code, trace on paper, select your answer. Feedback appears immediately. Target: 7/10 or higher means you are exam-ready on 2D arrays.
Score: 0 / 10
1.
int[][] grid = {{1,2,3},{4,5,6},{7,8,9}};
int result = 0;
for (int r = 0; r < grid.length; r++)
{
result += grid[r][r];
}
System.out.println(result);
What is printed?
2.
int[][] m = {{5,3,8},{2,7,4},{9,1,6}};
int val = m[0][0];
for (int r = 0; r < m.length; r++)
{
for (int c = 0; c < m[r].length; c++)
{
if (m[r][c] < val)
{
val = m[r][c];
}
}
}
System.out.println(val);
What is printed?
3.
int[][] t = {{1,2},{3,4},{5,6}};
System.out.println(t.length + " " + t[0].length);
What is printed?
4.
int[][] p = {{10,20,30},{40,50,60}};
int s = 0;
for (int c = 0; c < p[0].length; c++)
{
s += p[1][c];
}
System.out.println(s);
What is printed?
5. The following code is intended to print the elements of column 0, but it contains an error.
for (int c = 0; c < grid[0].length; c++)
{
System.out.println(grid[c][0]);
}
What is the error?
6.
int[][] d = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int count = 0;
for (int r = 0; r < d.length; r++)
{
for (int c = 0; c < d[r].length; c++)
{
if (d[r][c] % 3 == 0)
{
count++;
}
}
}
System.out.println(count);
What is printed?
7.
int[][] g = {{1,2},{3,4},{5,6},{7,8}};
for (int r = 0; r < g.length; r++)
{
for (int c = 0; c <= r; c++)
{
System.out.print(g[r][c] + " ");
}
System.out.println();
}
What is printed? (Note: g has 4 rows and 2 columns)
8. Which of the following correctly replaces every element in a 2D array with its absolute value?
9.
String[][] w = {{"A","B"},{"C","D"}};
System.out.println(w[1][0] + w[0][1]);
What is printed?
10. A 2D array has 6 rows and 4 columns. A method uses grid[0].length as the outer loop bound and grid.length as the inner loop bound. What happens?
❓ Frequently Asked Questions
How many 2D array questions are on the AP CSA exam?
Expect 8-12 MCQ involving 2D arrays plus the entire FRQ 4. Unit 4 is 30-40% of the exam, and 2D arrays are a major component of that weight.
What makes these questions hard?
These questions use non-obvious variable names, require multi-step tracing through nested loops, and include common traps like row/column confusion and off-by-one errors at matrix boundaries.
About the Author: Tanner Crow has 11+ years of AP Computer Science teaching experience, 1,845+ verified tutoring hours, and a 5.0 rating. His students score 5s at over double the national rate.
Book a tutoring session →
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.
34.8% of Tanner’s CSP students score 5s. The national average is 9.6%.
I’m a Student
I’m a Teacher
✓Free AP CSP Big Ideas cheat sheet (PDF)
✓Daily practice questions covering all 5 Big Ideas
✓Create Task tips that actually work — from a real AP teacher
✓Free class codes with student progress tracking
✓3 full practice exams + Top 100 questions for your class
✓Create Task guidance and pseudocode reference sheets
Which AP CS exams are you prepping for?
✓
You’re in!
Your Big Ideas cheat sheet is on its way.
No thanks, I’ll figure it out myself
Avg student improvement: 2+ score levels | Real AP teacher, not just a tutor
AP Cybersecurity — National Launch 2026–27
Get Early Access to AP Cyber
AP Cyber launches nationally fall 2026. Get in early to help shape the course — start free with Unit 1 and the free teacher gradebook.
✓
You’re in — you’re on the AP Cyber early-access list!
Tanner will follow up personally within 48 hours. Your feedback will directly shape what gets built.
Step 1 of 4
Early Access — Limited Spots
Who are you?
Are you a teacher or a student?
I’m a Teacher
I’m a Student
Free to start — Unit 1 and the teacher gradebook are always free, no credit card.
Founding teachers unlock all 5 units and get direct input on what we build.
Not interested right now
Step 2 of 4
Your School
Tell us about your class
Other AP CS courses you teach
Your Situation
Tell us about yourself
Step 3 of 4
Classroom Needs
What does your classroom need? (select all that apply)
How You Study
What would help you most? (select all that apply)
Step 4 of 4
Almost Done
Where should we send your early-access details?
Free gradebook + Unit 1 | Your feedback shapes the course | Built by a real AP teacher