Compound Condition In A While Loop
All of the following statements about the while loop above are true except:
public class ConditionLoop {
public static void main(String[] args) {
int a = 0;
while(a < 5 && a != 3) {
System.out.println(a);
a++;
}
}
}
A
The loop executes only while both conditions are satisfied.
B
The loop stops when a equals 3 because the second condition (a != 3) becomes false.
C
The loop prints numbers from 0 to 4, ignoring the fact that a is compared to 3 in the condition.
D
The && operator requires both conditions (a < 5 and a != 3) to be true for the loop to execute.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE