← Quiz: Java Control Flow: all 10 questions
Quiz: Java Control Flow · Question 10 of 10
What happens with int x = 3; if (x = 5) { ... } in Java?
What happens with int x = 3; if (x = 5) { ... } in Java?
- A.The condition is true because 5 is not zero
- B.x is compared with 5
- C.Compile error: an int cannot be used as a boolean condition
- D.The condition is false
Answer & explanation
Correct answer: Compile error: an int cannot be used as a boolean condition
Unlike C, Java requires a boolean in an if. Use == to compare.
Can you get the rest right without peeking?
Take the timed Quiz: Java Control Flow quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →