If Else If Control Structure
All of the following statements about the if-else-if structure in the above code snippet are true except:
public class Main {
public static void main(String[] args) {
int num = 15;
if (num < 10) {
System.out.println("Less than 10");
} else if (num < 20) {
System.out.println("Between 10 and 20");
} else {
System.out.println("20 or more");
}
}
}
A
The if-else-if structure evaluates conditions in order and executes the block corresponding to the first true condition.
B
The program will evaluate every condition even after a true condition is found.
C
Since num is 15, only the else-if condition (num < 20) is true and its block executes.
D
Once a true condition is encountered, subsequent conditions are not evaluated.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | mali.nehme | 1 | 1 | 0m 00s | 100 |
| #2 | sgarv2513 | 1 | 3 | 0m 00s | 80 |
| #3 | psak12 | 1 | 1 | 0m 33s | 67 |
| #4 | y.seong2027 | 1 | 1 | 0m 45s | 55 |
| #5 | kazvin.tjakradinata | 2 | 6 | 2m 19s | 21 |
| #6 | bommasam000 | 3 | 10 | 4m 06s | -16 |
| #7 | busemagngr | 1 | 1 | 2m 27s | -47 |
| #8 | namansoin000 | 1 | 1 | 2m 58s | -78 |
| #9 | chunxiangxu.cxu | 0 | 1 | 5m 20s | -330 |
| #10 | dobaonam8386 | 1 | 3 | 7m 14s | -354 |
Items per page:
10
1 – 10 of 12
APFIVE