Multiple choice

Given x is an integer, which of the following is a valid conditional?

  1. if (x > 2 or < 5)

  2. if (x = 4)

  3. if (x < 2 && x > 5)

  4. if (x)

Reveal answer Fill a bubble to check yourself
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.