Fiveable

💻AP Computer Science A Review

QR code for AP Computer Science A practice questions

Practice 3 - Analyze Code

Practice 3 - Analyze Code

Written by the Fiveable Content Team • Last updated June 2026
Verified for the 2027 exam
Verified for the 2027 examWritten by the Fiveable Content Team • Last updated June 2026
💻AP Computer Science A
Unit & Topic Study Guides

Frequently Asked Questions

Previous Exam Prep

Study Tools

Exam Skills

AP Cram Sessions 2021

Pep mascot

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.

Pep mascot
more resources to help you study

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 substring and indexing, since off-by-one slicing is common.
  • Understand access rules: private members cannot be used from another class, and class methods cannot be called on the class name when they are instance methods.
  • Recognize when if versus else if changes the result, since separate if statements 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)

</>Java
double 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)

</>Java
int 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)

</>Java
public 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)

</>Java
String 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)

</>Java
public 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 / 2 is 2, not 2.5, when both are ints.
  • Mishandling substring(a, b). It includes index a but stops before index b.
  • Miscounting loop iterations, especially confusing < with <=.
  • Treating separate if statements like else if. Multiple if blocks 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 private method 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.
Pep mascot
Upgrade your Fiveable account to print any study guide

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Click below to go to billing portal → update your plan → choose Yearly→ and select "Fiveable Share Plan". Only pay the difference

Plan is open to all students, teachers, parents, etc
Pep mascot
Upgrade your Fiveable account to export vocabulary

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Plan is open to all students, teachers, parents, etc
report an error
description

screenshots help us find and fix the issue faster (optional)

add screenshot