Logical OR Operator in an if Statement
Consider the following code segment. All of the following statements about the if statement are true EXCEPT:
public class Main {
public static void main(String[] args) {
int x = 10;
int y = 10;
if (x == 10 || y == 5) {
System.out.println("At least one condition is true.");
}
}
}
A
Since x equals 10, the condition x == 10 is satisfied, leading to the overall condition being true.
B
The logical OR operator means that only one of the conditions needs to be true for the if statement to execute.
C
The message is printed because with the OR operator only one true condition is needed.
D
The if condition requires both x to equal 10 and y to equal 5 in order for the message to be printed.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE