• 61 questions

AP Computer Science A Practice Test Operators and Conditions

Unofficial practice on Java operators and conditions for AP Computer Science A: Boolean expressions, if statements and De Morgan's law.

int a = 7; int b = 4; System.out.print(a - 3 >= b); What is printed?

Pick an answer, then press Check answer. Then you see Correct or Not quite, with the reason. Keys: 1 to 4 pick, Enter checks.

Print covers the next 25 questions. Share this set copies a link to the same questions in the same order.

More options

Unofficial practice questions, not affiliated with the College Board. Bank checked October 11, 2026.

All 61 questions

Topic 2.2: Boolean expressions and relational operators 9

  • double price = 19.99; int limit = 20; System.out.print(price < limit); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.2, essential knowledge 2.2.A.2
  • int a = 7; int b = 4; System.out.print(a - 3 >= b); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.2, essential knowledge 2.2.A.3
  • int n = 10; System.out.print(n / 4 == 2); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.2, essential knowledge 1.3.C.3 and 2.2.A.3
  • int score = 59; boolean pass = score > 59; System.out.print(pass); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.2, essential knowledge 2.2.A.2
  • int x = 5; int y = 5; Which expression is false? College Board, AP Computer Science A Course and Exam Description, topic 2.2, essential knowledge 2.2.A.2
  • The variable score is an int. What is the type of the expression score >= 60? College Board, AP Computer Science A Course and Exam Description, topic 2.2, essential knowledge 2.2.A.3
  • Which expression is true exactly when the int variable age is at least 13? Oracle, The Java Tutorials, "Equality, Relational, and Conditional Operators"; course topic 2.2
  • Which of these is not a relational operator in Java? Oracle, The Java Tutorials, "Equality, Relational, and Conditional Operators"; course topic 2.2
  • Which operator tests whether two int values are equal? Oracle, The Java Tutorials, "Equality, Relational, and Conditional Operators"; course topic 2.2
Show all 61 questions (52 more)

Topic 2.3: if statements 10

  • A programmer types if (x = 5) where x is an int variable. What happens? Oracle, The Java Language Specification, Java SE 17, section 14.9; course topic 2.3
  • An if statement has no else. What happens when its Boolean expression is false? Oracle, The Java Tutorials, "The if-then and if-then-else Statements"; course topic 2.3
  • In an if-else statement, when does the body of the else run? College Board, AP Computer Science A Course and Exam Description, topic 2.3, essential knowledge 2.3.A.4
  • int a = 4; if (a % 2 == 0) { a = a / 2; } else { a = a * 3 + 1; } System.out.print(a); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.3, essential knowledge 2.3.A.4
  • int k = 2; if (k > 5) k = k + 1; k = k * 10; System.out.print(k); What is printed? Oracle, The Java Tutorials, "The if-then and if-then-else Statements"; course topic 2.3
  • int n = 3; if (n > 5) { n = n + 10; } System.out.print(n); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.3, essential knowledge 2.3.A.3
  • int s = 85; String g = ""; if (s >= 80) { g = g + "B"; } if (s >= 70) { g = g + "C"; } System.out.print(g); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.3, essential knowledge 2.3.A.3
  • int t = 60; if (t >= 60) { System.out.print("P"); } else { System.out.print("F"); } What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.3, essential knowledge 2.3.A.4
  • int x = 7; if (x > 5) { x = x - 2; } if (x > 4) { x = x * 2; } System.out.print(x); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.3, essential knowledge 2.3.A.3
  • int x = 10; if (x < 10) { x = x + 5; } else { x = x - 5; } System.out.print(x); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.3, essential knowledge 2.3.A.4

Topic 2.4: Nested if statements 10

  • An if-else-if chain has four conditions and no trailing else. How many of its four bodies can run in one pass? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.3
  • int a = 2; int b = 50; if (a > 3) { if (b > 20) { System.out.print("X"); } } System.out.print("Z"); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.2
  • int a = 5; int b = 12; if (a > 3) { if (b > 20) { System.out.print("X"); } else { System.out.print("Y"); } } else { System.out.print("Z"); } What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.1
  • int h = 12; String part; if (h < 12) { part = "morning"; } else if (h < 18) { part = "afternoon"; } else { part = "evening"; } System.out.print(part); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.3
  • int n = 4; if (n > 10) if (n > 20) System.out.print("A"); else System.out.print("B"); System.out.print("C"); What is printed? Oracle, The Java Language Specification, Java SE 17, section 14.5; course topic 2.4
  • int s = 95; String g = "F"; if (s >= 70) { g = "C"; } else if (s >= 80) { g = "B"; } else if (s >= 90) { g = "A"; } System.out.print(g); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.3
  • int t = 68; String w; if (t > 85) { w = "hot"; } else if (t > 65) { w = "warm"; } else if (t > 45) { w = "cool"; } else { w = "cold"; } System.out.print(w); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.3
  • int x = 15; if (x > 10) { if (x % 2 == 0) { x = x / 2; } else { x = x + 1; } } else { x = 0; } System.out.print(x); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.1
  • One if statement is nested inside another. When is the inner one's Boolean expression evaluated? College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.2
  • Which single statement always does the same as this nested one? if (a > 0) { if (b > 0) { count++; } } College Board, AP Computer Science A Course and Exam Description, topic 2.4, essential knowledge 2.4.A.2

Topic 2.5: Compound Boolean expressions 12

  • boolean a = false; boolean b = false; System.out.print(!a || b); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.1
  • boolean a = true; boolean b = false; System.out.print(!a && b); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.1
  • For an int variable x, when is the expression x >= 1 || x <= 10 true? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.1
  • For Boolean variables a and b, in which case is a || b false? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.1
  • int a = 3; int b = 7; System.out.print(!(a > b) && b % a == 1); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.1
  • int age = 15; boolean hasPass = false; System.out.print(age >= 13 && age <= 19 || hasPass); What is printed? Oracle, The Java Tutorials, "Operators"; course topic 2.5
  • int d = 0; int n = 10; if (d != 0 && n / d > 2) { System.out.print("A"); } else { System.out.print("B"); } What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.2
  • int d = 0; int n = 10; if (n / d > 2 && d != 0) { System.out.print("A"); } else { System.out.print("B"); } What happens when this runs? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 1.3.C.6 and 2.5.A.2
  • int x = 5; if (x > 3 || x / 0 == 1) { System.out.print("ok"); } What happens when this runs? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.2
  • System.out.print(true || false && false); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.1
  • What is short-circuit evaluation of && and ||? Oracle, The Java Tutorials, "Equality, Relational, and Conditional Operators"; course topic 2.5
  • Which expression is true exactly when the int variable x is from 1 to 10, with both ends included? College Board, AP Computer Science A Course and Exam Description, topic 2.5, essential knowledge 2.5.A.1

Topic 2.6: Comparing Boolean expressions 12

  • A student claims that !(a && b) is the same as !a && !b. Which values show that the two differ? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.A.1
  • A truth table for a && b lists all four combinations of true and false for a and b. In how many of the four rows is a && b true? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.5.A.1 and 2.6.A.1
  • A truth table for a || b lists all four combinations of true and false for a and b. In how many of the four rows is a || b true? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.5.A.1 and 2.6.A.1
  • By De Morgan's law, which expression is equivalent to !(a && b)? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.A.2
  • By De Morgan's law, which expression is equivalent to !(a || b)? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.A.2
  • For int variables x and y, which expression is equivalent to !(x < y)? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.A.1
  • For int variables x and y, which expression is equivalent to !(x == 3 || y != 4)? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.A.2
  • For int variables x and y, which expression is equivalent to !(x > 5 && y <= 2)? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.A.2
  • String a = new String("hi"); String b = new String("hi"); System.out.print(a == b); System.out.print(" "); System.out.print(a.equals(b)); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.2.A.1 and 2.6.B.3
  • String name = null; Which test can be evaluated without throwing an exception? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.B.2
  • String s = new String("cat"); String t = s; System.out.print(s == t); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.B.1
  • What does it take to show that two Boolean expressions are equivalent? College Board, AP Computer Science A Course and Exam Description, topic 2.6, essential knowledge 2.6.A.1

Topics 1.3 and 1.6: Arithmetic and assignment operators 8

  • int a = 7; int b = 2; System.out.print(a / b); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 1.3, essential knowledge 1.3.C.3
  • int c = 5; c++; if (c > 5) { c *= 2; } System.out.print(c); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 1.6, essential knowledge 1.6.A.2
  • int d = 0; System.out.print(10 / d); What happens when this runs? College Board, AP Computer Science A Course and Exam Description, topic 1.3, essential knowledge 1.3.C.6
  • The int variable n is 0 or more. Which condition is true exactly when n is even? College Board, AP Computer Science A Course and Exam Description, topic 1.3, essential knowledge 1.3.C.4
  • int x = 9; x += 3; x /= 5; System.out.print(x); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 1.6, essential knowledge 1.6.A.1
  • System.out.print(2 + 3 * 4 % 5); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 1.3, essential knowledge 1.3.C.5
  • System.out.print(7 / 2.0); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 1.3, essential knowledge 1.3.C.2
  • System.out.print(17 % 5); What is printed? College Board, AP Computer Science A Course and Exam Description, topic 1.3, essential knowledge 1.3.C.4

How this list was compiled: Our own questions, written to the operator and condition topics of the College Board's AP Computer Science A Course and Exam Description, effective fall 2025, https://apcentral.collegeboard.org/media/pdf/ap-computer-science-a-course-and-exam-description.pdf, read 2026-10-11: 2.2 Boolean Expressions, 2.3 if Statements, 2.4 Nested if Statements, 2.5 Compound Boolean Expressions and 2.6 Comparing Boolean Expressions of Unit 2, with the arithmetic and compound assignment operators of topics 1.3 and 1.6. Each rule was read on 2026-10-11 in the essential knowledge statement, the Java Tutorials page or the Java Language Specification section named under its question, and every code segment was compiled and run on Java 17 to confirm its answer. Licence: Own work. Short quotations from the public documents named under each question.

How it works

This AP Computer Science A practice test on operators and conditions has 61 questions of our own. It is unofficial and not affiliated with the College Board, which owns AP.

Read the full guide

Where operators and conditions sit now

The College Board's course description, effective fall 2025 and read October 11, 2026, has four units. Conditions are topics 2.2 to 2.6 of Unit 2, Selection and Iteration: Boolean expressions (9 questions), if statements (10), nested if statements (10), compound Boolean expressions (12) and comparing Boolean expressions (12). Eight more questions cover the arithmetic and assignment operators of topics 1.3 and 1.6. The description gives topics no weights, so the spread is ours.

How the answers are checked

Each rule is cited to an essential knowledge statement of the course description, a page of Oracle's Java Tutorials or a section of the Java Language Specification. Every code segment was compiled and run on Java 17.

  • The order is ! first, then &&, then ||. When a line mixes them, add parentheses and trace it again.
  • Put the guard first: in d != 0 && n / d > 2 the division is skipped when d is 0.
  • Use == for int, double and boolean values. For the contents of a String use equals; == asks whether two references are one object.

Questions and answers

What unit is Boolean expressions and if statements in AP Computer Science A?

Unit 2, Selection and Iteration, in the course description effective fall 2025. The loop topics of the same unit, 2.7 to 2.12, are not on this page.

How much of the AP Computer Science A exam is Unit 2?

Between 25 and 35% of the multiple-choice section, by the course description. That figure is for the whole unit, loops included. The exam runs 3 hours, with 42 multiple-choice and 4 free-response questions.

What do AP Computer Science A practice tests on operators and conditions cover?

Relational operators such as == and >=, the logical operators !, && and ||, short-circuit evaluation, if, if-else and if-else-if statements, nested ifs, De Morgan's law, and comparing object references with == and equals.

What is short-circuit evaluation in Java?

When the first operand of && is false, or the first operand of || is true, the result is already settled and the second operand is not evaluated. A test such as x != 0 && 10 / x > 1 relies on it.

Are these real AP Computer Science A exam questions?

No. The College Board owns the real questions, and none appears here, even in other words. Every question was written for this page from the topics the course description lists.