Overview
AP Computer Science A Practice 3 - Analyze Code is the skill of reading existing Java code and figuring out what it produces or why it fails. You trace statement execution to determine output, predict results from code that uses data and procedural abstractions, and explain why a segment will not compile or work as intended.
This practice shows up more than any other on the multiple-choice section. On the exam, Practice 3 carries roughly 37 to 53 percent of the multiple-choice weighting, so getting comfortable tracing code is one of the highest-value things you can do.
This guide breaks down the four subskills (3.A, 3.B, 3.C, 3.D), shows how each looks on real question types, and gives you a workflow for tracing code without losing track.

What Practice 3 - Analyze Code Means
Practice 3 is about analysis, not writing. You are given working or broken code and asked to reason about it. The four subskills cover four kinds of analysis:
- 3.A Determine the result or output based on statement execution order in an algorithm.
- 3.B Determine the result or output based on code that contains data abstractions.
- 3.C Determine the result or output based on code that contains procedural abstractions.
- 3.D Explain why a code segment will not compile or work as intended and modify the code to correct the error.
All four are tested in multiple-choice questions only. None of them appear as standalone free-response tasks, though the same reasoning helps you debug your own FRQ code.
What This Practice Requires
You need to act like the computer and step through the code line by line, keeping track of every variable's value as it changes.
For each subskill that means:
- 3.A: Follow control flow through assignments, conditionals, and loops in the exact order they run. Order matters, especially with loops and reassignment.
- 3.B: Predict output when the code stores data in structures like arrays, ArrayLists, 2D arrays, or objects with instance variables. You track what is inside the structure as it changes.
- 3.C: Predict output when the code calls methods. You apply what a method returns or does without always seeing its full body, using its header, parameters, and return type.
- 3.D: Spot the reason a segment is wrong, then choose the change that fixes it. Errors can be compile errors (calling a private method from outside, using the wrong type) or logic errors (a wrong starting value, a misordered condition).
Skills You Need for This Practice
- Track variable values as a table while you read. Write down each variable and update it every line.
- Know operator behavior, especially integer division, casting, and the modulus operator
%. - Understand
Math.random()ranges.(int)(Math.random() * n)gives a whole number from 0 to n minus 1. - Trace loops by counting iterations and watching the loop variable's start, condition, and update.
- Know String methods like
substringand indexing, since off-by-one slicing is common. - Understand access rules:
privatemembers cannot be used from another class, and class methods cannot be called on the class name when they are instance methods. - Recognize when
ifversuselse ifchanges the result, since separateifstatements can overwrite earlier decisions.
How It Shows Up on the AP Exam
Practice 3 lives in the multiple-choice section, which is 42 questions in 90 minutes and counts for 55 percent of the exam. This practice is the largest slice of that section.
Questions usually do one of these:
- Show a code segment and ask exactly what is printed.
- Ask which value could be printed when randomness is involved.
- Ask how many times a statement runs.
- Show a method that does not work and ask which change fixes it.
All four units are fair game, so a Practice 3 question can use a String, an object, an ArrayList, or a 2D array as its setting.
Examples Across the Course
Here are varied examples that mirror how each subskill appears across different units.
3.A with casting and integer division (Unit 1)
</>Javadouble q = 15.0; int r = 2; double x = (int) (q / r); double y = q / r; System.out.println(x + " " + y);
q / r is 15.0 / 2, which is 7.5 because q is a double. Casting to int gives 7, then stored in a double as 7.0. The second y stays 7.5. Output is 7.0 7.5.
3.A with nested loops (Unit 2)
</>Javaint j = 1; while (j < 4) { for (int k = 0; k <= 4; k++) { System.out.println("hello"); } j++; }
The outer loop runs for j equal to 1, 2, 3, so 3 times. The inner loop runs for k equal to 0 through 4, so 5 times. Total is 3 times 5, which is 15.
3.B with an ArrayList (Unit 4)
</>Javapublic void reviseList(ArrayList<Integer> list) { for (int i = 0; i < list.size(); i++) { int temp = list.get(i); if (temp % 2 == 1) { list.set(i, temp + 1); } } }
Called on [1, 2, 3, 3, 2, 1], every odd value gets 1 added. Odd values become even, even values stay. Result is [2, 2, 4, 4, 2, 2].
3.C with String methods (Unit 1 and 2)
</>JavaString str1 = "LMNOP"; String str2 = str1.substring(3); str2 += str1.substring(2, 3);
str1.substring(3) starts at index 3 and goes to the end, giving "OP". str1.substring(2, 3) is index 2 up to but not including 3, giving "N". So str2 becomes "OPN".
3.D with a logic error (Unit 4)
</>Javapublic int findMaxValue(int[] ranges) { int max = 0; // line 4 for (int value : ranges) { if (value > max) { max = value; } } return max; }
This fails when all elements are negative, because starting max at 0 means a negative max can never beat it. The fix is to change line 4 to int max = ranges[0]; so the starting value is an actual element.
How to Practice Practice 3 - Analyze Code
These are practical study habits, not official exam rules.
- Build a variable trace table for every practice question. Columns for each variable, a new row each time a value changes.
- For loops, write the loop variable's value at the start of each pass and check the condition before deciding to run again.
- For randomness questions, compute the smallest and largest values each expression can produce, then check which answer falls in range.
- When debugging, test the broken code on a tricky input such as all negatives, an empty structure, or the first and last index.
- After choosing an answer, plug it back in to confirm it matches the requested output exactly.
- Practice across all four units so you are comfortable with Strings, objects, ArrayLists, and 2D arrays as the code setting.
Common Mistakes
- Forgetting integer division.
5 / 2is2, not2.5, when both are ints. - Mishandling
substring(a, b). It includes indexabut stops before indexb. - Miscounting loop iterations, especially confusing
<with<=. - Treating separate
ifstatements likeelse if. Multipleifblocks can each run and overwrite a result. - Starting a max search at 0 or a min search at a huge value when the data can be all negative or all positive.
- Calling a
privatemethod or instance method incorrectly, such as using the class name instead of an object reference. - Trusting your memory of a variable instead of writing the trace down. Most output errors come from a value you forgot to update.
Quick Review
- Practice 3 is reading code and predicting output or finding the error. It is multiple-choice only.
- 3.A: follow execution order, watch loops, casting, and integer math.
- 3.B: track what is inside arrays, ArrayLists, 2D arrays, and objects.
- 3.C: apply what called methods return or do.
- 3.D: find why code breaks and pick the correct fix.
- This practice is the biggest part of the multiple-choice section, so tracing carefully pays off.
- Always trace with a table, test edge cases, and verify your answer by plugging it back in.