int n = 1;
while (n < 100) {
n *= 2;
}Which for-loop produces the same final value of n?
- A
for (int n = 0; n < 100; n *= 2) {}
- Bcheck_circle
for (int n = 1; n < 100; n *= 2) {}
- C
for (int n = 1; n < 100; n++) {}
- D
for (int n = 1; n <= 100; n /= 2) {}
Explanation
The update n *= 2 in the for-loop header reproduces the doubling step until n is no longer less than 100.