High school & admissions

AP Computer Science A — Practice Questions flashcards

6 of 55 questions free to study here · 4 topics · the whole deck is built into Willys

Multiple-choice practice questions, one best answer each, on Java expressions, Strings, boolean logic, loops, classes, arrays, ArrayList, 2D arrays, searching, sorting and recursion.

Practice deck · part of AP Computer Science A · written against: College Board AP Computer Science A Course and Exam Description (Java subset; 2025 revision). Updated 2026-10-10.

Study the free sample

6 questions from the deck as they are. Flip, rate yourself, filter by topic; your progress stays in this browser.

The 6 sample questions as a list
  1. What is printed by the following code?
    double d = 9.7;
    int n = (int) d + (int) -2.4;
    System.out.println(n);

    A) 7
    B) 6
    C) 7.3
    D) 8
    A) 7

    Each cast truncates toward zero, so (int) d is 9 and (int) -2.4 is -2, giving 7. Getting 6 means treating the negative cast as rounding down to -3.
    Using Objects and Methods › Primitive Types and Casting
  2. What is printed by the following code?
    int total = 17;
    int count = 4;
    double avg = total / count;
    System.out.println(avg);

    A) 4.25
    B) 5.0
    C) 4.0
    D) 4
    C) 4.0

    total / count divides two ints, so integer division gives 4 before the value is widened to a double and printed as 4.0. A cast such as (double) total / count would be needed to get 4.25.
    Using Objects and Methods › Primitive Types and Casting
  3. For int variables a and b, which expression is equivalent to !(a < 3 || b != 0)?

    A) a >= 3 && b == 0
    B) a >= 3 || b == 0
    C) a < 3 && b != 0
    D) a > 3 && b == 0
    A) a >= 3 && b == 0

    By De Morgan's law, negating an || gives an && of the negated parts: the negation of a < 3 is a >= 3 and the negation of b != 0 is b == 0. Keeping || negates the parts but forgets to swap the operator.
    Selection and Iteration › Boolean Logic
  4. What is printed by the following code?
    int k = 0;
    boolean b = (k == 0) || (10 / k > 1);
    System.out.println(b);

    A) Nothing; an ArithmeticException is thrown
    B) false
    C) Nothing; the code does not compile
    D) true
    D) true

    The left side of || is true, so short-circuit evaluation skips the right side and the division by zero never happens. The whole expression is true.
    Selection and Iteration › Boolean Logic
  5. The class Thermostat declares private double temp;. Code in a different class runs Thermostat t = new Thermostat(); t.temp = 70.0;. What is the result?

    A) The code compiles but throws an exception when run
    B) The code compiles and sets temp to 70.0
    C) The assignment causes a compile-time error
    D) The code compiles, but the assignment is ignored
    C) The assignment causes a compile-time error

    A private instance variable can be used only by code inside its own class, so the compiler rejects the assignment. Outside code must go through a public method such as a mutator.
    Class Creation › Anatomy of a Class
  6. What is printed by the following code?
    int[] a = {4, 8, 15, 16, 23};
    int s = 0;
    for (int i = 1; i < a.length; i += 2) s += a[i];
    System.out.println(s);

    A) 24
    B) 47
    C) 42
    D) 66
    A) 24

    The loop visits indices 1 and 3 only, adding 8 and 16. Summing the values at the even indices instead would give 42.
    Data Collections › Arrays

Unlock the whole deck

You are studying a free 6-question sample. All 55 questions of AP Computer Science A — Practice Questions, the other 2 AP Computer Science A decks, and spaced-repetition scheduling are built into Willys. 14-day free trial, then $14.99 a year.

In Willys, tap Exam Library at the top of your Decks (or Browse Exam Library… under the + button), find the exam on its shelf or by search, tick it and tap Add.

More AP Computer Science A decks

← All AP Computer Science A decks, with the study guide and topic outline.

About these cards

Review status: Second-reader reviewed, with corrections applied.

Checked against:

  • Topic outline follows the College Board AP Computer Science A Course and Exam Description (revised course, first exam May 2026), Units 1–4 (the AP name is used nominatively; no course or exam text reproduced).
  • Every code trace and compile check was verified by compiling and running the equivalent Java (OpenJDK); behavior checked against the Java SE API documentation (reference only, no text copied).

These are independent study notes written for Willys. They are not official exam material, may contain mistakes, and are no substitute for your course, your teacher or the exam owner's own publications. Found an error? Tell us — corrections ship as a new version of the deck.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this product.

Use of these pages is covered by our Terms of Use.