---
title: "AP CSA Practice 3 Analyze Code Study Guide"
description: "Learn AP Computer Science A Practice 3 - Analyze Code: trace output, handle abstractions, and find code errors with worked MCQ examples."
canonical: "https://fiveable.me/ap-comp-sci-a/computational-thinking-practices/practice-3-analyze-code/study-guide/IYHLM9WkVvtxjEvjmj1X"
type: "study-guide"
subject: "AP Computer Science A"
unit: "**Computational Thinking Practices"
lastUpdated: "2026-06-17"
---

# AP CSA Practice 3 Analyze Code Study Guide

## Summary

Learn AP Computer Science A Practice 3 - Analyze Code: trace output, handle abstractions, and find code errors with worked MCQ examples.

## Guide

## Overview

[AP Computer Science A](/ap-comp-sci-a "fv-autolink") 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](/ap-comp-sci-a/key-terms/compile "fv-autolink") 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](/ap-comp-sci-a/key-terms/tracing "fv-autolink") 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](/ap-comp-sci-a/key-terms/algorithm "fv-autolink").
- **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](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink")'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](/ap-comp-sci-a/key-terms/object "fv-autolink") with [instance variables](/ap-comp-sci-a/key-terms/instance-variables "fv-autolink"). You track what is inside the structure as it changes.
- **3.C:** Predict output when the code calls [methods](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink"). You apply what a method returns or does without always seeing its full body, using its header, parameters, and [return type](/ap-comp-sci-a/key-terms/return-type "fv-autolink").
- **3.D:** Spot the reason a segment is wrong, then choose the change that fixes it. Errors can be compile errors (calling a [private](/ap-comp-sci-a/key-terms/private "fv-autolink") 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](/ap-comp-sci-a/unit-4/introduction-to-using-data-sets/study-guide/fq4I4p0XINBBV56xQfTx "fv-autolink") while you read. Write down each variable and [update](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt "fv-autolink") it every line.
- Know operator behavior, especially [integer division](/ap-comp-sci-a/key-terms/integer-division "fv-autolink"), [casting](/ap-comp-sci-a/unit-1/casting-and-ranges-of-variables/study-guide/kW3XXEIwJwVRXFx3ntdC "fv-autolink"), 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](/ap-comp-sci-a/unit-1/string-methods/study-guide/SltCtk8JxBIgHcMfG6G4 "fv-autolink") 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](/ap-comp-sci-a/unit-1/using-the-math-class/study-guide/6e652tzJOa5eE5mjPATE "fv-autolink") cannot be called on the class name when they are [instance methods](/ap-comp-sci-a/unit-3/static-variables-and-methods/study-guide/zzhHVbXBRCZQ7ng3EeWX "fv-autolink").
- 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](/ap-comp-sci-a/unit-4/developing-algorithms-using-arraylists/study-guide/MKbteieYvLOpWIwfqiND "fv-autolink"), 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](/ap-comp-sci-a/unit-1 "fv-autolink"))**

```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](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment "fv-autolink") 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.
