AP Computer Science A · Topic 3.5

Compound Boolean Expressions Practice

Part of Boolean Expressions and if Statements.

Practice questions

33

Want a predicted score for the whole AP CSA exam? Take the 20-question diagnostic and Lumi will plan the rest.

Sample questions

5 of 33 — sign in to practice the rest with adaptive difficulty and mastery tracking.

  1. Sample 1difficulty 1/5

    boolean b = true;
    System.out.println(!b);

    What is printed?

    • A

      false

      check_circle
    • B

      true

    • C

      !true

    • D

      1

    Why

    The ! operator negates a boolean value. !true evaluates to false.

  2. Sample 2difficulty 2/5

    int a = 5;
    int b = 10;
    boolean result = (a < b) && (b > 0);
    System.out.println(result);

    What is printed?

    • A

      true

      check_circle
    • B

      false

    • C

      5

    • D

      10

    Why

    Both (a < b) which is (5 < 10) = true and (b > 0) which is (10 > 0) = true. true && true = true.

  3. Sample 3difficulty 2/5

    if (!(x < 5)) {
        return true;
    }
    return false;

    Which expression is equivalent to !(x < 5)?

    • A

      x != 5

    • B

      x <= 5

    • C

      x > 5

    • D

      x >= 5

      check_circle

    Why

    The negation of x < 5 is x >= 5 (x is at least 5).

  4. Sample 4difficulty 2/5

    int n = 50;
    if (n >= 0 && n <= 100) {
      System.out.println("valid");
    } else {
      System.out.println("invalid");
    }

    What is printed?

    • A

      valid

      check_circle
    • B

      0

    • C

      invalid

    • D

      100

    Why

    50 is between 0 and 100 inclusive, so both parts of the && are true, and "valid" is printed.

  5. Sample 5difficulty 2/5

    <code>(5 > 3) && (4 < 2)</code> evaluates to

    • A

      1

    • B

      Compile error

    • C

      false

      check_circle
    • D

      true

    Why

    AND requires both true; second is false → result false.