AP Computer Science A · Topic 2.8

Wrapper Classes: Integer and Double Practice

Part of Using Objects.

Practice questions

14

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 14 — sign in to practice the rest with adaptive difficulty and mastery tracking.

  1. Sample 1difficulty 2/5

    Integer x = 7;
    int y = x + 3;
    System.out.println(y);

    What is printed?

    • A

      10

      check_circle
    • B

      7

    • C

      37

    • D

      73

    Why

    The Integer x is auto-unboxed to int 7 when used in arithmetic, so y = 7 + 3 = 10.

  2. Sample 2difficulty 3/5

    String s = "42";
    int n = Integer.parseInt(s);
    System.out.println(n + 1);

    What is printed?

    • A

      421

    • B

      42

    • C

      Error

    • D

      43

      check_circle

    Why

    Integer.parseInt converts the string "42" to the int 42; adding 1 gives 43.

  3. Sample 3difficulty 3/5

    Double d = 4.5;
    double r = d * 2;
    System.out.println(r);

    What is printed?

    • A

      9.0

      check_circle
    • B

      4.5

    • C

      9

    • D

      8.5

    Why

    d is auto-unboxed to double 4.5; multiplying by 2 yields 9.0.

  4. Sample 4difficulty 3/5

    Which is the wrapper class for the <code>int</code> primitive?

    • A

      Integer

      check_circle
    • B

      Int

    • C

      IntegerType

    • D

      INT

    Why

    <code>Integer</code> wraps int; <code>Double</code> wraps double; <code>Boolean</code> wraps boolean.

  5. Sample 5difficulty 3/5

    String s = "3.14";
    double d = Double.parseDouble(s);
    System.out.println(d * 2);

    What is printed?

    • A

      6.28

      check_circle
    • B

      Error

    • C

      6

    • D

      3.14

    Why

    Double.parseDouble converts the string "3.14" to the double value 3.14; multiplied by 2 the result is 6.28.