AP Computer Science A · Topic 2.8
Wrapper Classes: Integer and Double Practice
Part of Using Objects.
Practice questions
14
Sample questions
5 of 14 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 2/5
Integer x = 7; int y = x + 3; System.out.println(y);What is printed?
- Acheck_circle
10
- 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.
- A
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
- Dcheck_circle
43
Why
Integer.parseInt converts the string "42" to the int 42; adding 1 gives 43.
- A
Sample 3difficulty 3/5
Double d = 4.5; double r = d * 2; System.out.println(r);What is printed?
- Acheck_circle
9.0
- B
4.5
- C
9
- D
8.5
Why
d is auto-unboxed to double 4.5; multiplying by 2 yields 9.0.
- A
Sample 4difficulty 3/5
Which is the wrapper class for the <code>int</code> primitive?
- Acheck_circle
Integer
- B
Int
- C
IntegerType
- D
INT
Why
<code>Integer</code> wraps int; <code>Double</code> wraps double; <code>Boolean</code> wraps boolean.
- A
Sample 5difficulty 3/5
String s = "3.14"; double d = Double.parseDouble(s); System.out.println(d * 2);What is printed?
- Acheck_circle
6.28
- 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.
- A