AP Computer Science A · Topic 1.4
Compound Assignment Operators Practice
Part of Primitive Types.
Practice questions
5
Sample questions
5 of 5 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 2/5
x = x + 5;Which statement is equivalent?
- A
x++ 5;
- B
++x = 5;
- Ccheck_circle
x += 5;
- D
x =+ 5;
Why
The compound assignment x += 5 is shorthand for x = x + 5.
- A
Sample 2difficulty 2/5
int n = 20; n /= 6; System.out.println(n);What is printed?
- Acheck_circle
3
- B
3.33
- C
2
- D
4
Why
n /= 6 sets n to n / 6 with integer division, so 20 / 6 = 3.
- A
Sample 3difficulty 2/5
int x = 10; x += 3; x *= 2; System.out.println(x);What is printed?
- Acheck_circle
26
- B
20
- C
23
- D
16
Why
x += 3 makes x equal to 13, then x *= 2 makes x equal to 26.
- A
Sample 4difficulty 2/5
Given <code>int x = 10;</code>, what is <code>x</code> after <code>x += 5;</code>?
- A
10
- Bcheck_circle
15
- C
5
- D
50
Why
<code>x += 5;</code> is equivalent to <code>x = x + 5;</code>.
- A
Sample 5difficulty 3/5
int n = 23; n %= 6; System.out.println(n);What is printed?
- A
0
- B
3
- C
4
- Dcheck_circle
5
Why
n %= 6 sets n equal to n % 6; 23 % 6 = 5.
- A