Given x is an integer, which of the following is a valid conditional?
-
if (x > 2 or < 5)
-
if (x = 4)
-
if (x < 2 && x > 5)
-
if (x)
C
Correct answer
Explanation
In Java, conditional statements inside an if-statement must evaluate to a boolean value. Option C uses the valid logical AND operator (&&) to combine two valid boolean comparisons, even though the condition itself can never be true. Other options either use invalid syntax or try to use an integer as a boolean.