AP CSA Ultimate Practice Exam

AP Computer Science A
Ultimate Practice Exam

42 Multiple-Choice Questions • 90 Minutes • 2025–2026 Curriculum

Study Mode: Check your answer after each question and get immediate feedback.

0 / 42 answered

Exam Overview

Questions: 42 multiple-choice (4 answer choices each)

Time: 1 hour and 30 minutes

Units Covered: Unit 1 (Using Objects and Methods), Unit 2 (Selection and Iteration), Unit 3 (Class Creation), Unit 4 (Data Collections)

Format: Matches the official 2025–2026 AP CSA Exam structure administered through Bluebook

Scoring: Based only on the number of correct answers. No penalty for incorrect answers.

Notes: Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Assume that method calls not prefixed with an object or class name appear within the context of an enclosing class. Unless otherwise noted, assume parameters are not null and preconditions are satisfied.

1. Unit 1

Consider the following code segment.

String s = "PROGRAMMING";
String t = s.substring(3, 7);
String u = t.substring(1);
System.out.println(u);

What is printed as a result of executing the code segment?

Answer: Csubstring(3, 7) yields "GRAM". substring(1) on that yields "RAM". (A) omits the second substring. (B) confuses substring(1) with removal of the last character. (D) applies an extra off-by-one.

2. Unit 1

Consider the following code segment.

int a = 17;
int b = 4;
double c = (double)(a / b);
System.out.println(c);

What is printed as a result of executing the code segment?

Answer: Aa / b performs integer division: 4. The cast to double applies after the division, producing 4.0. (B) would require casting before division. (C) is wrong because the result is stored as a double.

3. Unit 1

Consider the following code segment.

String w = "blanket";
int idx = w.indexOf("an");
System.out.println(w.substring(idx + 1, idx + 4));

What is printed as a result of executing the code segment?

Answer: DindexOf("an") returns 2. substring(3, 6) yields "nke". (A) uses idx as the start without adding 1. (C) assumes 1-based indexing.

4. Unit 1

Consider the following method and code segment.

public static int transform(int x)
{
    x = x + 3;
    return x * 2;
}

// In another method:
int a = 5;
int b = transform(a);
System.out.println(a + " " + b);

What is printed as a result of executing the code segment?

Answer: D — Primitive parameters are copies. a remains 5. Inside transform, x becomes 8, and 8 * 2 = 16 is returned. (A) incorrectly assumes a is modified. (B) applies only * 2 to the original value. (C) combines both errors.

5. Unit 1

Consider the following code segment.

String p = "TIGER";
String q = "TIGER";
String r = new String("TIGER");

boolean v1 = (p == q);
boolean v2 = (p == r);
boolean v3 = p.equals(r);

Which of the following correctly describes the values of v1, v2, and v3 after the code segment executes?

Answer: B — String literals are interned, so p == q is true. new String() creates a distinct object, so p == r is false. .equals() compares content, so v3 is true.

6. Unit 1

Consider the following code segment.

System.out.println("Value: " + 3 + 4);
System.out.println("Value: " + (3 + 4));

What is printed as a result of executing the code segment?

Answer: C — In line 1, left-to-right evaluation with a String produces concatenation: "Value: " + 3"Value: 3""Value: 34". In line 2, parentheses force arithmetic first: 3 + 4 = 7, then concatenation produces "Value: 7".

7. Unit 1

Consider the following code segment.

String a = "COMPUTER";
String b = a;
a = a.substring(2, 6);
System.out.println(a + " " + b);

What is printed as a result of executing the code segment?

Answer: Db = a copies the reference. a = a.substring(2, 6) creates a new String "MPUT" and reassigns a. Strings are immutable, so b still references "COMPUTER". (A) incorrectly assumes b tracks a’s reassignment. (B) treats substring(2, 6) as inclusive on the end index.

8. Unit 1

Consider the following code segment.

int x = 5;
double y = x;       // Line 1
int z = y;           // Line 2
String s = "" + x;   // Line 3
int w = (int) y;     // Line 4

Which line will cause a compile-time error?

Answer: A — Line 2 attempts to assign a double to an int without a cast, which is a lossy conversion and causes a compile error. Line 1 is a widening conversion (allowed). Line 3 uses concatenation with "" to produce a String (allowed). Line 4 uses an explicit cast (allowed).

9. Unit 2

Consider the following code segment.

int a = 5;
int b = 12;
int c = 8;

if (a > c || b < 10)
{
    c = a + b;
}
else if (c > a && c < b)
{
    c = b - a;
}
else
{
    c = a * b;
}
System.out.println(c);

What is printed as a result of executing the code segment?

Answer: C5 > 8 is false, 12 < 10 is false; first condition fails. 8 > 5 is true and 8 < 12 is true; else-if executes: 12 - 5 = 7. (A) enters the first if. (D) assumes no branch executes.

10. Unit 2

Consider the following code segment.

int k = 1;
int total = 0;
while (k < 20)
{
    total += k;
    k *= 3;
}
System.out.println(total);

What is printed as a result of executing the code segment?

Answer: A — Iterations: total=1,k=3; total=4,k=9; total=13,k=27. Loop exits (27 ≥ 20). (B) includes k=27 in the sum. (D) stops one iteration early.

11. Unit 2

Consider the following code segment.

for (int j = 1; j <= 4; j++)
{
    for (int k = j; k <= 4; k++)
    {
        System.out.print("*");
    }
    System.out.println();
}

What is printed as a result of executing the code segment?

Answer: A — When j=1, inner loop runs 4 times; j=2, 3 times; j=3, 2 times; j=4, 1 time. (B) reverses the direction. (C) reads <= as < in the outer loop. (D) assumes inner loop always starts at 1.

12. Unit 2

Consider the following Boolean expression.

!(a > b) && !(b < c)

Which of the following is equivalent to the expression above?

Answer: D!(a > b) simplifies to a <= b; !(b < c) simplifies to b >= c. (A) uses strict inequalities, missing equality cases. (B) incorrectly changes && to ||. (C) applies De Morgan’s incorrectly—distributing negation over && requires changing to ||.

13. Unit 2

Consider the following code segment.

String s = "ALGORITHMS";
String result = "";
for (int i = 0; i < s.length(); i += 3)
{
    result += s.substring(i, i + 1);
}
System.out.println(result);

What is printed as a result of executing the code segment?

Answer: A — Indices visited: 0→A, 3→O, 6→T, 9→S. (B) starts at index 1. (C) increments by 2. (D) increments by 1.

14. Unit 2

Consider the following code segment.

int x = 10;
int y = 3;

if (x % y == 0)
{
    System.out.print("W");
}
else if (x / y > 3)
{
    System.out.print("X");
}
else if (x % y != 0 && x / y >= 3)
{
    System.out.print("Y");
}
else
{
    System.out.print("Z");
}

What is printed as a result of executing the code segment?

Answer: D10 % 3 = 1 (not 0), skip W. 10 / 3 = 3 (integer division), 3 > 3 is false, skip X. 1 != 0 is true and 3 >= 3 is true, so Y prints. The key distinction is > vs. >=.

15. Unit 2

Consider the following code segment, where n is a positive integer.

int count = 0;
for (int i = 1; i <= n; i++)
{
    for (int j = 0; j < i; j++)
    {
        count++;
    }
}

Which of the following best describes the value of count after the code segment executes?

Answer: B — Inner loop runs i times per iteration. Total = 1 + 2 + … + n = n(n+1)/2. (A) assumes inner loop always runs n times. (C) uses the wrong summation formula.

16. Unit 2

Consider the following method.

public static String process(String str)
{
    String result = "";
    for (int k = str.length() - 1; k >= 0; k--)
    {
        result += str.substring(k, k + 1);
    }
    return result;
}

What is returned by the call process("CORAL")?

Answer: B — The loop traverses from the last index to 0, appending each character, reversing the string. (D) suspects an out-of-bounds error, but substring(k, k + 1) at the last valid index is safe.

17. Unit 2

The following method is intended to return true if the parameter val is a multiple of both 3 and 5, and false otherwise.

public static boolean check(int val)
{
    if (val % 3 == 0)
    {
        return true;
    }
    if (val % 5 == 0)
    {
        return true;
    }
    return false;
}

For which of the following values of val does the method NOT work as intended?

Answer: C — The method uses OR logic (separate if-return statements) instead of AND. For 9: 9 % 3 == 0 is true, so it returns true, but 9 is not a multiple of both 3 and 5. (A) and (D) are multiples of both. (B) is a multiple of neither.

18. Unit 2

Consider the following method.

public static int mystery(int n)
{
    int count = 0;
    while (n != 1)
    {
        if (n % 2 == 0)
        {
            n = n / 2;
        }
        else
        {
            n = 3 * n + 1;
        }
        count++;
    }
    return count;
}

What value is returned by the call mystery(6)?

Answer: C — n=6→3 (count=1), 3→10 (2), 10→5 (3), 5→16 (4), 16→8 (5), 8→4 (6), 4→2 (7), 2→1 (8). Returns 8. (A) confuses the input with the count. (D) stops when n first reaches an odd value.

19. Unit 2

Consider the following code segment.

int[] arr = {2, 4, 6};
int idx = 3;
if (idx < arr.length && arr[idx] > 5)
{
    System.out.print("A");
}
else
{
    System.out.print("B");
}

What is printed as a result of executing the code segment?

Answer: Aidx < arr.length evaluates to 3 < 3, which is false. Because of short-circuit evaluation with &&, arr[idx] is never accessed, so no exception occurs. The else branch prints "B". (C) incorrectly assumes both sides of && are always evaluated.

20. Unit 2

Consider the following code segment.

int m = 5;
int p = 2;
while (m < 30)
{
    m += p;
    p++;
}
System.out.println(m + " " + p);

What is printed as a result of executing the code segment?

Answer: C — m=7,p=3 → m=10,p=4 → m=14,p=5 → m=19,p=6 → m=25,p=7 → m=32,p=8. Loop exits. (A) and (D) incorrectly assume m lands exactly on 30.

21. Unit 2

Consider the following code segment, where a and b are boolean variables.

boolean result = (a || b) && !(a && b);

Which of the following expressions is equivalent to the value of result?

Answer: C — The expression (a || b) && !(a && b) evaluates to true when exactly one operand is true—which is the definition of XOR. In Java, a != b on booleans produces exactly this behavior. (A) is AND (both true). (B) is OR (at least one true). (D) is true only when both are false.

22. Unit 3

Consider the following class.

public class Tracker
{
    private int count;
    private double total;

    public Tracker()
    {
        count = 0;
        total = 0.0;
    }

    public void record(double val)
    {
        double total = this.total + val;
        count++;
    }

    public double getAverage()
    {
        return total / count;
    }
}

A Tracker object is created and record is called several times. getAverage is then called. Which of the following best explains why the method does NOT return the expected average?

Answer: Bdouble total = this.total + val; declares a local variable that shadows the instance variable. The instance total remains 0.0.

23. Unit 3

Consider the following class definition.

public class Vessel
{
    private String label;
    private int capacity;

    public Vessel(String label, int capacity)
    {
        /* missing code */
    }
}

Which of the following should replace /* missing code */ so that the constructor initializes the instance variables correctly?

Answer: Cthis distinguishes the instance variable from the parameter when names match. (A) assigns the parameters to themselves. (B) uses the class name for non-static access. (D) creates new local variables.

24. Unit 3

Consider the following class.

public class Widget
{
    private int code;
    private double rating;

    public Widget(int c, double r)
    {
        code = c;
        rating = r;
    }

    public Widget(int c)
    {
        code = c;
        rating = 0.0;
    }

    public int getCode()
    {
        return code;
    }

    public double getRating()
    {
        return rating;
    }
}

Which of the following code segments will compile without error?

I. Widget w1 = new Widget(50, 3.7);

II. Widget w2 = new Widget(25);

III. Widget w3 = new Widget();

Answer: B — I matches the two-parameter constructor. II matches the one-parameter constructor. III fails because no default no-arg constructor exists when other constructors are defined.

25. Unit 3

Consider the following class.

public class Marker
{
    private int level;

    public Marker(int startLevel)
    {
        level = startLevel;
    }

    public boolean isHigher(Marker other)
    {
        /* missing code */
    }

    public int getLevel()
    {
        return level;
    }
}

The isHigher method is intended to return true if the level of this Marker is greater than the level of other. Which of the following should replace /* missing code */?

Answer: B — Within the same class, private fields of another instance are accessible. (A) and (D) compare an int to a Marker object. (C) applies > to object references, which is not valid.

26. Unit 3

A class is being designed to represent an item in a store. The class will have a name (String), a price (double), and a quantity (int). The attributes should not be directly accessible from outside the class.

Which of the following is the most appropriate partial implementation?

Answer: D — Instance variables should be private; the constructor and accessors should be public. (A) creates local variables in the constructor that shadow the instance variables—the fields are never initialized. (B) declares name as public, violating encapsulation. (C) uses a private constructor, preventing object creation from other classes.

27. Unit 4

Consider the following code segment.

int[] data = {3, 7, 2, 8, 5};
for (int val : data)
{
    if (val < 5)
    {
        val = 0;
    }
}
System.out.println(data[0] + " " + data[2]);

What is printed as a result of executing the code segment?

Answer: B — In a for-each loop, val is a copy of each element. Assigning to val does not modify the original array. (A) assumes the array is modified.

28. Unit 4

Consider the following code segment.

ArrayList data = new ArrayList();
data.add(7);
data.add(4);
data.add(9);
data.add(2);
data.add(6);

for (int k = data.size() - 1; k >= 0; k--)
{
    if (data.get(k) % 2 == 0)
    {
        data.remove(k);
    }
}
System.out.println(data);

What is printed as a result of executing the code segment?

Answer: A — Backward traversal removes all even values (6, 2, 4) without index-shifting issues. (B) misses the 4 removal. (C) keeps the evens instead.

29. Unit 4

Consider the following method.

public static void modify(int[][] arr)
{
    for (int r = 0; r < arr.length; r++)
    {
        for (int c = 0; c < arr[r].length; c++)
        {
            if (r != c)
            {
                arr[r][c] = 0;
            }
        }
    }
}

When the method is called on a square 2D array, which of the following best describes what the method does?

Answer: D — The condition r != c is true for all off-diagonal positions, setting those to 0. Diagonal elements (where r == c) are skipped. (A) ignores the condition. (B) reverses which elements are zeroed.

30. Unit 4

Consider the following code segment.

int[] arr = {10, 20, 30, 40, 50};
for (int k = 0; k < arr.length - 1; k++)
{
    arr[k] = arr[k + 1];
}
arr[arr.length - 1] = arr[0];

Which of the following represents the contents of arr after the code segment executes?

Answer: D — The loop shifts elements left: {20, 30, 40, 50, 50}. Then arr[4] = arr[0], but arr[0] is now 20 (the original 10 was overwritten), giving {20, 30, 40, 50, 20}. (A) assumes the original first element is preserved.

31. Unit 4

Consider the following method.

public static void process(int[] arr)
{
    for (int k = 0; k < arr.length - 1; k++)
    {
        if (arr[k] > arr[k + 1])
        {
            int temp = arr[k];
            arr[k] = arr[k + 1];
            arr[k + 1] = temp;
        }
    }
}

If int[] vals = {6, 2, 8, 1, 5} and the call process(vals) is made, which of the following represents the contents of vals after the call?

Answer: C — Single pass: k=0: 6>2, swap → {2,6,8,1,5}. k=1: 6<8, no swap. k=2: 8>1, swap → {2,6,1,8,5}. k=3: 8>5, swap → {2,6,1,5,8}. (A) assumes full sort. (B) assumes arrays are passed by value.

32. Unit 4

Consider the following code segment.

ArrayList items = new ArrayList();
items.add("red");
items.add("green");
items.add("blue");
items.add(1, "yellow");
items.set(3, "purple");
items.remove(0);
System.out.println(items);

What is printed as a result of executing the code segment?

Answer: A — After adds: [red, green, blue]. add(1, "yellow"): [red, yellow, green, blue]. set(3, "purple"): [red, yellow, green, purple]. remove(0): [yellow, green, purple]. (B) forgets the remove. (D) confuses the remove index.

33. Unit 4

Consider the following code segment.

int[][] mat = {{2, 4, 6},
               {8, 10, 12},
               {14, 16, 18},
               {20, 22, 24}};
int count = 0;
for (int[] row : mat)
{
    for (int val : row)
    {
        if (val % 4 == 0)
        {
            count++;
        }
    }
}
System.out.println(count);

What is printed as a result of executing the code segment?

Answer: B — Multiples of 4: 4, 8, 12, 16, 20, 24. Count = 6.

34. Unit 4

The following method is intended to return the number of elements in arr that are greater than their immediate predecessor.

public static int analyze(int[] arr)
{
    int count = 0;
    for (int k = 1; k <= arr.length; k++)
    {
        if (arr[k] > arr[k - 1])
        {
            count++;
        }
    }
    return count;
}

The method does NOT work as intended. Which of the following changes will make the method work correctly?

Answer: D — When k = arr.length, arr[k] causes an ArrayIndexOutOfBoundsException. (B) would access arr[-1]. (C) changes the logic but does not fix the crash.

35. Unit 4

Consider the following code segment.

int[][] grid = {{5, 1, 3},
                {4, 7, 2},
                {8, 6, 9}};
int result = 0;
for (int r = 0; r < grid.length; r++)
{
    for (int c = r + 1; c < grid[0].length; c++)
    {
        result += grid[r][c];
    }
}
System.out.println(result);

What is printed as a result of executing the code segment?

Answer: A — The inner loop starts at c = r + 1, summing elements above the diagonal. r=0: 1+3=4. r=1: 2. r=2: no iterations. Total = 6. (B) includes the diagonal. (C) sums all elements. (D) sums below the diagonal.

36. Unit 4

Consider the following method, which is intended to return true if all elements in the ArrayList are positive, and false otherwise.

public static boolean validate(ArrayList list)
{
    for (int val : list)
    {
        if (val <= 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    return true;
}

Which of the following best describes the error in this method?

Answer: C — On the first iteration, both branches contain a return statement, so the method exits immediately. The else { return true; } should be removed.

37. Unit 4

Consider the following method.

public static int compute(int n)
{
    if (n <= 1)
    {
        return 1;
    }
    return n * compute(n - 2);
}

What value is returned by the call compute(7)?

Answer: A — 7 * compute(5) = 7 * 5 * compute(3) = 7 * 5 * 3 * compute(1) = 7 * 5 * 3 * 1 = 105. (B) sums instead of multiplying. (D) is 7! (standard factorial).

38. Unit 4

Consider the following code segment.

ArrayList words = new ArrayList();
words.add("cat");
words.add("dog");
words.add("fish");
words.add("bird");

for (int k = 0; k < words.size(); k++)
{
    if (words.get(k).length() == 3)
    {
        words.set(k, words.get(k).toUpperCase());
    }
}
System.out.println(words);

What is printed as a result of executing the code segment?

Answer: D"cat" and "dog" each have length 3, so they are replaced with their uppercase forms. "fish" (4) and "bird" (4) do not meet the condition. (A) ignores the length check. (B) assumes toUpperCase() returns a new String that is not stored back (it is, via set). (C) miscounts the length of "bird".

39. Unit 4

Consider the following code segment.

ArrayList nums = new ArrayList();
nums.add(10);
nums.add(20);
nums.add(30);
nums.add(40);

for (int k = 0; k < nums.size(); k++)
{
    if (nums.get(k) > 15)
    {
        nums.remove(k);
    }
}
System.out.println(nums);

What is printed as a result of executing the code segment?

Answer: B — k=0: 10, no remove. k=1: 20 removed → [10, 30, 40]. k=2: 40 removed → [10, 30]. 30 was skipped because the removal shifted it into the index that was just checked.

40. Unit 4

Consider the following method, which is intended to return true if two arrays contain the same elements in the same order.

public static boolean match(int[] a, int[] b)
{
    for (int k = 0; k < a.length; k++)
    {
        if (a[k] != b[k])
        {
            return false;
        }
    }
    return true;
}

For which of the following test cases does the method return an incorrect result?

I. a = {1, 2, 3}, b = {1, 2, 3}

II. a = {1, 2}, b = {1, 2, 3}

III. a = {3, 2, 1}, b = {1, 2, 3}

Answer: A — The method lacks a length check. II: a.length is 2, so only the first two elements are compared; both match, returning true—but the arrays differ. I: correctly returns true. III: at k=0, 3 != 1, correctly returns false.

41. Unit 4

A school system has the following data sets available.

• Data set 1 contains an entry for each student. Each entry includes the student’s name, grade level, and school ID.

• Data set 2 contains an entry for each student. Each entry includes the student’s school ID and a list of courses the student is enrolled in.

• Data set 3 contains an entry for each course. Each entry includes the course name and the number of students enrolled.

• Data set 4 contains an entry for each school. Each entry includes the school name and the total number of students.

A researcher wants to determine whether students in grade 10 are more likely to be enrolled in a science course than students in grade 11. Which two data sets should be combined?

Answer: C — Grade level (set 1) and course enrollment (set 2), linked by school ID. Set 3 has only aggregate counts. Set 4 has no course data.

42. Unit 4

Consider the following code segment.

int[][] board = new int[3][4];
int val = 1;
for (int c = 0; c < board[0].length; c++)
{
    for (int r = 0; r < board.length; r++)
    {
        board[r][c] = val;
        val++;
    }
}
System.out.println(board[1][2]);

What is printed as a result of executing the code segment?

Answer: B — Filled column by column. Col 0: 1,2,3. Col 1: 4,5,6. Col 2: 7,8,9. board[1][2] = 8. (A) confuses row-major order. (C) reads board[0][2].

* This is a rough, unofficial estimate for practice purposes only. Actual AP scores are determined by the College Board using a composite of MCQ and FRQ sections.

Want a Teacher to Walk You Through Every Question?

Join the AP CSA MCQ Bootcamp — a live 2-hour session covering all 42 question types with the strategies that helped 54.5% of students score a 5.

View Bootcamp Details →

Frequently Asked Questions

How many questions are on the 2025–2026 AP CSA exam?

The AP Computer Science A exam has 42 multiple-choice questions with 4 answer choices each (A through D), plus 4 free-response questions. The MCQ section is worth 55% of the total score and the FRQ section is worth 45%.

What units are covered on the AP CSA exam?

The 2025–2026 AP CSA exam covers 4 units: Unit 1 (Using Objects and Methods, 15–25%), Unit 2 (Selection and Iteration, 25–35%), Unit 3 (Class Creation, 10–18%), and Unit 4 (Data Collections, 30–40%). This practice exam matches those exact weights.

Is there a penalty for wrong answers on the AP CSA exam?

No. The AP CSA exam score is based only on the number of correct answers. There is no penalty for incorrect or unanswered questions, so you should always answer every question even if you are unsure.

What is removed from the AP CSA exam for 2025–2026?

The 2025–2026 AP CSA exam removes inheritance, polymorphism, extends, super, and interfaces. It adds File/Scanner text file reading and recursion tracing (trace only, not writing recursive methods). This practice exam is fully aligned to the current curriculum.

What is the difference between Study Mode and Test Mode?

Study Mode lets you check your answer after each question and see the explanation immediately, so you learn as you go. Test Mode simulates the real exam: you answer all 42 questions first, then score at the end to see your results all at once.

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]