int n = 1;
while (n < 16) {
n *= 2;
}
System.out.println(n);What is printed?
- Acheck_circle
16
- B
8
- C
32
- D
15
Explanation
n doubles each time: 1, 2, 4, 8, 16. When n becomes 16 the condition n < 16 is false and the loop exits. n is 16.
AP Computer Science A· difficulty 2/5
int n = 1;
while (n < 16) {
n *= 2;
}
System.out.println(n);What is printed?
16
8
32
15
Explanation
n doubles each time: 1, 2, 4, 8, 16. When n becomes 16 the condition n < 16 is false and the loop exits. n is 16.
Want 10 more like this — adaptive to your weak spots?
What does this print? <codefor (int i = 0; i < 5; i++) { if (i == 3) break; System.out.print(i); } </code</pre…
chevron_right"Read numbers until -1 is entered, then stop" — best loop pattern…
chevron_rightWhat does this print? <codeint i = 5; do { System.out.print(i); } while (i < 3); </code</pre…
chevron_right