• 84 questions
  • Checked November 2026

AP Computer Science A Practice Exam

Unofficial AP CSA questions on all four units: read the Java, pick an answer and see it traced.

public static double mix(int a, double b) { return a + b; } Which call to mix does not compile?
More options

Unofficial practice questions, not affiliated with the College Board. Checked November 30, 2026.

All 84 questions with answers

Checked against: apcentral.collegeboard.org.

Unit 1: Using Objects and Methods

AP Computer Science A Course and Exam Description, effective fall 2025.

  • class Lamp { private int watts; private String color; public Lamp() { watts = 40; color = "white"; } public Lamp(int w) { watts = w; color = "white"; } public Lamp(int w, String c) { watts = w; color = c; } } Study the class. Which constructor call does not compile? Answer: new Lamp("red"). Topic 1.13 (1.13.A.3); run on Java 17
  • double d = 7.9; int n = (int) d * 2; System.out.print(n); What is printed? Answer: 14. Topic 1.5 (1.5.A.2); run on Java 17
  • double x = -8.6; System.out.print((int) (x - 0.5)); What is printed? Answer: -9. Topic 1.5 (1.5.A.4); run on Java 17
  • int a = 3; int b = a; a = a + 4; b = b * a; System.out.print(a + " " + b); What is printed? Answer: 7 21. Topic 1.4 (1.4.A.2); run on Java 17
Show all 84 questions

Unit 1: Using Objects and Methods, continued

  • int k = 17; k -= 5; k /= 2; k %= 4; System.out.print(k); What is printed? Answer: 2. Topic 1.6 (1.6.A.1); run on Java 17
  • int m = Integer.MAX_VALUE; m++; System.out.print(m < 0); What is printed? Answer: true. Topic 1.5 (1.5.B.3); run on Java 17
  • int r = "cat".compareTo("car"); What is true of r? Answer: It is greater than 0. Topic 1.15 (1.15.B.2); run on Java 17
  • public static double mix(int a, double b) { return a + b; } Which call to mix does not compile? Answer: mix(2.5, 4). Topic 1.9 (1.9.B.3); run on Java 17
  • public static int twice(int n) { return 2 * n; } public static int less(int n) { return n - 3; } System.out.print(twice(less(8)) - less(twice(4))); Trace the code. What does the code print? Answer: 5. Topic 1.9 (1.9.B.5); run on Java 17
  • String s = null; System.out.print(s.indexOf("a")); What happens when this runs? Answer: A NullPointerException is thrown. Topic 1.14 (1.14.A.2); run on Java 17
  • String w = "backpack"; System.out.print(w.substring(4) + w.substring(1, 3) + w.indexOf("ack")); What is printed? Answer: packac1. Topic 1.15 (1.15.B.2); run on Java 17
  • System.out.print("A"); System.out.println("B"); System.out.print("C"); How does the output look? Answer: AB on one line and C on the next. Topic 1.3 (1.3.A.1); run on Java 17
  • System.out.print("Say \"hi\" \\ bye"); What is printed? Answer: Say "hi" \ bye. Topic 1.3 (1.3.B.3); run on Java 17
  • System.out.print(19 / 4 + 19 % 4 * 2); What is printed? Answer: 10. Topic 1.3 (1.3.C.5); run on Java 17
  • System.out.print(Math.pow(5, 2) + Math.abs(-6) + Math.sqrt(9)); What is printed? Answer: 34.0. Topic 1.11 (1.11.A.2); run on Java 17
  • Which expression gives a random int from 5 to 12, with both ends possible? Answer: (int) (Math.random() * 8) + 5. Topic 1.11 (1.11.A.3); run on Java 17
  • Which mistake does the compiler find before the program runs? Answer: A statement with no semicolon at its end. Topic 1.1 (1.1.C.1)

Unit 2: Selection and Iteration

AP Computer Science A Course and Exam Description, effective fall 2025.

  • A loop reads ten int values. max starts at 0, and each value greater than max replaces it. For which values is the final max wrong? Answer: Ten negative values. Topic 2.9 (2.9.A.1)
  • A recipe says: stir until the sugar has dissolved. Which building block of an algorithm is that? Answer: Repetition. Topic 2.1 (2.1.A.4)
  • class Coin { private int v; public Coin(int x) { v = x; } public int getV() { return v; } } Coin a = new Coin(5); Coin b = a; Coin c = new Coin(5); System.out.print((a == b) + " " + (a == c) + " " + (a.getV() == c.getV())); Trace the code. What does the code print? Answer: true false true. Topic 2.6 (2.6.B.1); run on Java 17
  • for (int i = 0; i < n; i++) { for (int j = 0; j < 5; j++) { c++; } } How many times is c++ carried out, for an int n above 0? Answer: 5 * n. Topic 2.12 (2.12.A.1); run on Java 17
  • for (int i = 5; i > 0; i--) { System.out.print(i); } Which code prints the same? Answer: int i = 5; while (i > 0) { System.out.print(i); i--; }. Topic 2.8 (2.8.A.3); run on Java 17
  • for (int r = 1; r <= 3; r++) { for (int k = 0; k < r; k++) { System.out.print(r); } System.out.print(" "); } What is printed? Answer: 1 22 333. Topic 2.11 (2.11.A.1); run on Java 17
  • if (a) { return true; } else { return b; } a and b are boolean variables. Which expression always gives the value that is returned here? Answer: a || b. Topic 2.6 (2.6.A.1); run on Java 17
  • int c = 0; for (int i = 1; i < 64; i *= 2) { c++; } System.out.print(c); What is printed? Answer: 6. Topic 2.12 (2.12.A.1); run on Java 17
  • int c = 0; for (int i = 1; i <= 4; i++) { for (int j = i; j <= 4; j++) { c++; } } System.out.print(c); What is printed? Answer: 10. Topic 2.11 (2.11.A.1); run on Java 17
  • int c = 0; for (int i = 2; i < 30; i += 5) { c++; } System.out.print(c); What is printed? Answer: 6. Topic 2.8 (2.8.A.2); run on Java 17
  • int n = 100; int c = 0; while (n > 5) { n /= 3; c++; } System.out.print(n + " " + c); What is printed? Answer: 3 3. Topic 2.7 (2.7.B.1); run on Java 17
  • int n = 352; int r = 0; while (n > 0) { r = r * 10 + n % 10; n /= 10; } System.out.print(r); What is printed? Answer: 253. Topic 2.9 (2.9.A.1); run on Java 17
  • int p = 12; if (p % 3 == 0) { p += 5; } if (p > 15) { p -= 10; } else { p *= 2; } System.out.print(p); What is printed? Answer: 7. Topic 2.3 (2.3.A.4); run on Java 17
  • int s = 0; for (int i = 1; i <= 10; i++) { if (i % 4 == 1) { s += i; } } System.out.print(s); What is printed? Answer: 15. Topic 2.8 (2.8.A.2); run on Java 17
  • int t = 0; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (i < j) { t += i * j; } } } System.out.print(t); Trace the code. What does the code print? Answer: 11. Topic 2.11 (2.11.A.1); run on Java 17
  • int t = 10; while (t < 10) { t++; } System.out.print(t); What is printed? Answer: 10. Topic 2.7 (2.7.A.3); run on Java 17
  • public static int f(int n) { int r = 0; while (n > 0) { r += n % 10; n /= 10; } return r; } System.out.print(f(4072)); What is printed? Answer: 13. Topic 2.9 (2.9.A.1); run on Java 17
  • public static int g(int n) { int c = 0; for (int i = 1; i <= n; i++) { if (n % i == 0) { c++; } } return c; } System.out.print(g(18)); Trace the code. What does the code print? Answer: 6. Topic 2.9 (2.9.A.1); run on Java 17
  • public static String size(int n) { if (n < 10) { return "S"; } else if (n < 20) { return "M"; } return "L"; } System.out.print(size(20) + size(10) + size(9)); Trace the code. What does the code print? Answer: LMS. Topic 2.4 (2.4.A.3); run on Java 17
  • String s = "a1b2c3"; String r = ""; for (int i = 0; i < s.length(); i += 2) { r += s.substring(i, i + 1); } System.out.print(r); Trace the code. What does the code print? Answer: abc. Topic 2.10 (2.10.A.1); run on Java 17
  • String s = "banana"; int c = 0; for (int i = 0; i < s.length() - 1; i++) { if (s.substring(i, i + 2).equals("an")) { c++; } } System.out.print(c); Trace the code. What does the code print? Answer: 2. Topic 2.10 (2.10.A.1); run on Java 17
  • String s = "loop"; for (int i = 0; i <= s.length(); i++) { System.out.print(s.substring(i, i + 1)); } What happens when this runs? Answer: loop is printed and then an exception is thrown. Topics 2.10 and 1.15 (1.15.B.1); run on Java 17
  • String s = "part"; String r = ""; for (int i = 0; i < s.length(); i++) { r = s.substring(i, i + 1) + r; } System.out.print(r); Trace the code. What does the code print? Answer: trap. Topic 2.10 (2.10.A.1); run on Java 17
  • while (n != 0) { n = n - 2; } For which starting value of the int n does this loop never end? Answer: 7. Topic 2.7 (2.7.A.2); run on Java 17
  • x and y are int variables. Which expression is true exactly when one of them, but not both, is above 0? Answer: (x > 0) != (y > 0). Topic 2.5 (2.5.A.1); run on Java 17

Unit 3: Class Creation

AP Computer Science A Course and Exam Description, effective fall 2025.

  • A constructor receives an ArrayList and stores it in an instance variable. Why should it store a copy? Answer: Code that holds the original could change the object’s state. Topic 3.4 (3.4.A.3)
  • A method is rewritten to run faster. Its signature and what it does stay the same. What has to change in the code that calls it? Answer: Nothing. Topic 3.1 (3.1.A.6)
  • A programmer finds a useful piece of code that its author has not released as open source. What is needed before it goes into a program? Answer: Permission for its use. Topic 3.2 (3.2.A.3)
  • class Box { private int n; private String label; private boolean full; public String show() { return n + " " + label + " " + full; } } Box b = new Box(); System.out.print(b.show()); Trace the code. What does the code print? Answer: 0 null false. Topic 3.4 (3.4.A.5); run on Java 17
  • class Counter { private int n; public void add() { n++; } public int get() { return n; } } public static void work(Counter c) { c.add(); c = new Counter(); c.add(); c.add(); } Counter k = new Counter(); work(k); System.out.print(k.get()); Trace the code. What does the code print? Answer: 1. Topic 3.6 (3.6.A.1); run on Java 17
  • class Cup { private int size; public Cup(int size) { size = size; } public int getSize() { return size; } } Cup c = new Cup(8); System.out.print(c.getSize()); Trace the code. What does the code print? Answer: 0. Topic 3.8 (3.8.A.2); run on Java 17
  • class Dot { private int x; public Dot(int x) { this.x = x; } public int getX() { return this.x; } public boolean same(Dot d) { return this.x == d.x; } public static int twice() { return 2 * this.x; } } Study the class. Why does this class not compile? Answer: twice is static, and a class method has no this. Topic 3.9 (3.9.A.3); run on Java 17
  • class Pet { private static int made = 0; private int id; public Pet() { made++; id = made; } public int getId() { return id; } public static int getMade() { return made; } } Pet a = new Pet(); Pet b = new Pet(); Pet c = new Pet(); System.out.print(b.getId() + " " + Pet.getMade()); Trace the code. What does the code print? Answer: 2 3. Topic 3.7 (3.7.B.1); run on Java 17
  • class Safe { private int code; public Safe(int c) { code = c; } public boolean opens(int c) { return c == code; } private void reset() { code = 0; } } Another class has Safe s = new Safe(7); Which statement compiles there? Answer: boolean b = s.opens(7);. Topic 3.3 (3.3.A.6); run on Java 17
  • class Tank { private int liters; public Tank(int n) { liters = n; } public void fill(int n) { liters += n; } public int getLiters() { return liters; } } Tank t = new Tank(10); t.fill(5); Tank u = t; u.fill(20); System.out.print(t.getLiters()); Trace the code. What does the code print? Answer: 35. Topic 3.5 (3.5.A.6); run on Java 17
  • public static int find(String s, String t) { for (int i = 0; i < s.length(); i++) { if (s.substring(i, i + 1).equals(t)) { return i; } } return -1; } System.out.print(find("pepper", "p") + find("pepper", "z")); Trace the code. What does the code print? Answer: -1. Topic 3.5 (3.5.A.4); run on Java 17
  • public static void bump(int n) { n = n + 10; } int n = 5; bump(n); System.out.print(n); What is printed? Answer: 5. Topic 3.5 (3.5.A.8); run on Java 17

Unit 4: Data Collections

AP Computer Science A Course and Exam Description, effective fall 2025.

  • A binary search looks for 30 in {3, 8, 12, 17, 21, 30, 44}, with the middle index at (low + high) / 2. How many elements does it compare with 30? Answer: 2. Topic 4.17 (4.17.B.1); run on Java 17
  • A data set holds the heights of college basketball players. Which question can it not answer? Answer: How tall is the average adult? Topic 4.1 (4.1.C.1)
  • A double[][] named m is traversed with nested enhanced for loops. What is the type of the outer loop variable? Answer: double[]. Topic 4.12 (4.12.A.2); run on Java 17
  • A loan program gives one group of applicants unfair results again and again because of how it was made. What is that called? Answer: Algorithmic bias. Topic 4.1 (4.1.B.1)
  • A selection sort puts {6, 9, 3, 4, 1} in increasing order. How does the array look after the second pass? Answer: {1, 3, 9, 4, 6}. Topic 4.15 (4.15.A.2); run on Java 17
  • An enhanced for loop goes through an ArrayList and removes elements from it on the way. What can result? Answer: A ConcurrentModificationException. Topic 4.9 (4.9.A.4)
  • An insertion sort puts {8, 5, 7, 2, 6} in increasing order. How does the array look after 5 and 7 have been inserted? Answer: {5, 7, 8, 2, 6}. Topic 4.15 (4.15.A.3); run on Java 17
  • ArrayList<Integer> v = new ArrayList<Integer>(); v.add(5); v.add(3); v.add(1); v.remove(1); System.out.print(v); What is printed? Answer: [5, 1]. Topic 4.8 (4.8.A.5); run on Java 17
  • ArrayList<String> w = new ArrayList<String>(); w.add("a"); w.add("b"); w.add(1, "c"); w.set(0, "d"); w.remove(2); System.out.print(w); Trace the code. What does the code print? Answer: [d, c]. Topic 4.8 (4.8.A.5); run on Java 17
  • int[] a = new int[4]; a[1] = 6; a[3] = a[1] / 4; System.out.print(a[0] + a[2] + a[3]); What is printed? Answer: 1. Topic 4.3 (4.3.A.3); run on Java 17
  • int[] a = {1, 2, 3}; for (int i = 0; i < a.length; i++) { int t = a[i]; a[i] = a[a.length - 1 - i]; a[a.length - 1 - i] = t; } for (int x : a) { System.out.print(x + " "); } Trace the code. What does the code print? Answer: 1 2 3. Topic 4.5 (4.5.A.1); run on Java 17
  • int[] a = {1, 2, 3}; for (int x : a) { x = x * 10; } System.out.print(a[0] + " " + a[2]); What is printed? Answer: 1 3. Topic 4.4 (4.4.A.4); run on Java 17
  • int[] a = {3, 6, 9, 12}; int f = a[0]; for (int i = 0; i < a.length - 1; i++) { a[i] = a[i + 1]; } a[a.length - 1] = f; for (int x : a) { System.out.print(x + " "); } Trace the code. What does the code print? Answer: 6 9 12 3. Topic 4.5 (4.5.A.1); run on Java 17
  • int[] a = {4, 8, 15}; System.out.print(a[a.length]); What happens when this runs? Answer: An ArrayIndexOutOfBoundsException is thrown. Topic 4.3 (4.3.A.6); run on Java 17
  • int[] a = {6, 2, 9, 5}; for (int i = 1; i < a.length; i++) { a[i] = a[i - 1]; } for (int x : a) { System.out.print(x + " "); } Trace the code. What does the code print? Answer: 6 6 6 6. Topic 4.5 (4.5.A.1); run on Java 17
  • int[] a = {7, 8, 10}; int s = 0; for (int x : a) { s += x; } System.out.print((double) (s / a.length)); What is printed? Answer: 8.0. Topic 4.5 (4.5.A.1); run on Java 17
  • int[][] g = new int[3][5]; System.out.print(g.length + " " + g[0].length); What is printed? Answer: 3 5. Topic 4.11 (4.11.A.6); run on Java 17
  • int[][] m = { {1, 2, 3}, {4, 5, 6} }; for (int c = 0; c < m[0].length; c++) { for (int r = 0; r < m.length; r++) { System.out.print(m[r][c] + " "); } } Trace the code. What does the code print? Answer: 1 4 2 5 3 6. Topic 4.12 (4.12.A.1); run on Java 17
  • int[][] m = { {2, 0, 1}, {3, 5, 8}, {4, 6, 7} }; int s = 0; for (int i = 0; i < m.length; i++) { s += m[i][m.length - 1 - i]; } System.out.print(s); Trace the code. What does the code print? Answer: 10. Topic 4.13 (4.13.A.1); run on Java 17
  • Integer k = 8; int n = k + 2; String s = "15"; System.out.print(n + Integer.parseInt(s)); What is printed? Answer: 25. Topic 4.7 (4.7.A.4); run on Java 17
  • Merge sort splits {7, 3, 8, 1} into {7, 3} and {8, 1}. What do the two halves hold just before the last merge? Answer: {3, 7} and {1, 8}. Topic 4.17 (4.17.C.2)
  • public static boolean up(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] >= a[i + 1]) { return false; } } return true; } Study the method. For which array does up return true? Answer: {2, 5, 9}. Topic 4.5 (4.5.A.1); run on Java 17
  • public static int f(int n) { if (n < 10) { return n; } return f(n / 10) + 1; } System.out.print(f(4072)); What is printed? Answer: 7. Topic 4.16 (4.16.A.2); run on Java 17
  • public static int f(int[][] m, int k) { int s = 0; for (int i = 0; i < m.length; i++) { s += m[i][k]; } return s; } What does f return? Answer: The sum of column k. Topic 4.13 (4.13.A.1); run on Java 17
  • public static int last(int[] a, int t) { for (int i = a.length - 1; i >= 0; i--) { if (a[i] == t) { return i; } } return -1; } int[] a = {4, 7, 4, 9}; System.out.print(last(a, 4)); Trace the code. What does the code print? Answer: 2. Topic 4.14 (4.14.A.1); run on Java 17
  • public static int pairs(ArrayList<String> w) { int c = 0; for (int i = 0; i < w.size(); i++) { for (int j = i + 1; j < w.size(); j++) { if (w.get(i).equals(w.get(j))) { c++; } } } return c; } The list w holds "Bo", "Al", "Bo", "Bo". What does pairs(w) return? Answer: 3. Topic 4.10 (4.10.A.1); run on Java 17
  • public static String g(String s) { if (s.length() <= 1) { return s; } return g(s.substring(1)) + s.substring(0, 1); } System.out.print(g("star")); Trace the code. What does the code print? Answer: rats. Topic 4.17 (4.17.A.1); run on Java 17
  • Scanner in = new Scanner(new File("temps.txt")); int c = 0; while (in.hasNext()) { int t = in.nextInt(); if (t > 30) { c++; } } in.close(); System.out.print(c); The file temps.txt holds 28 31 35 30 40. What does the code print? Answer: 3. Topic 4.6 (4.6.A.9); run on Java 17
  • String line = "Ana,12,blue"; String[] p = line.split(","); System.out.print(p.length + p[1]); What is printed? Answer: 312. Topic 4.6 (4.6.A.8); run on Java 17
  • v is an ArrayList<Integer> that holds 2, 4, 5, 6. for (int i = 0; i < v.size(); i++) { if (v.get(i) % 2 == 0) { v.remove(i); } } Trace the loop. What does v hold after the loop? Answer: 4, 5. Topic 4.9 (4.9.A.2); run on Java 17

How this list was compiled: Our own questions, written to the four units of the College Board’s AP Computer Science A Course and Exam Description, effective fall 2025, apcentral.collegeboard.org, and to the exam page apcentral.collegeboard.org, both read November 30, 2026. Each question names the essential knowledge statement it rests on. Every question with code was compiled and run on Java 17 (OpenJDK), on November 30, 2026 or December 1, 2026.

How it works

This AP Computer Science A practice exam has 84 multiple-choice questions of our own in Java. It is unofficial and not affiliated with or endorsed by the College Board, which owns AP.

Read the full guide

The real AP CSA exam

By the College Board's exam page, read November 30, 2026, Section I asks 42 multiple-choice questions in 90 minutes, 55% of the score. Section II asks four free-response questions in 90 minutes. Exam mode sets 42 questions against 90 minutes.

Four units, by weight

Using Objects and Methods 15 to 25%, Selection and Iteration 25 to 35%, Class Creation 10 to 18%, Data Collections 30 to 40%, by the course description effective fall 2025. The bank holds 17, 25, 12 and 30.

How the answers are checked

Every question with code was compiled and run on Java 17. Each names its topic and its statement in the course description.

  • Write the variables in a column and cross out old values. Then check the first and the last pass of each loop.

Questions and answers

Is there an AP Computer Science practice test PDF?

Yes, as a printout. Print the question sheet takes 42 of the 84 questions, from all four units, with a key. Choose Save as PDF in the print window.

Is this AP Computer Science practice test multiple choice only?

Yes: four choices, one right. For the four free-response questions, use the College Board's past ones on AP Central, and note that those before 2026 follow the old format.

What is on the AP Computer Science A exam?

Java: methods and strings, if statements and loops, writing a class, arrays, ArrayLists, 2D arrays, text files, searching, sorting and tracing recursion. Writing inheritance and writing recursive code are outside the course.

Is AP Computer Science A the same as Principles?

No. A is a Java programming course; Principles (CSP) is about computing in general, with pseudocode. For that one take the AP CSP practice test.

Which Java methods do I have to know for the AP CSA exam?

Those of the Java Quick Reference, which is in the Bluebook app: String, Math, Integer, Double, ArrayList, File, Scanner and Object. Besides System.out.print and println, the questions here use no others.