# boolean quiz

Greenhorn
Posts: 6
write an expression that evaluates to true if and only if the value of the integer variable x is equal to zero

Ernest Friedman-Hill
author and iconoclast
Marshal
Posts: 24212
35
OK, tell us your answer, and we'll tell you if it's right.

Greenhorn
Posts: 6
x<=0 is 1

Ernest Friedman-Hill
author and iconoclast
Marshal
Posts: 24212
35
The question asks for an expression that is true if x is equal to 0. "==" means "is equal to" in Java. Want to try again?

Greenhorn
Posts: 6
(x == 0)is true

Ernest Friedman-Hill
author and iconoclast
Marshal
Posts: 24212
35
Well, I think you've got it; I'm not sure if the "is true" is part of your answer or not. The correct answer is "x == 0"; you'd use such an expression in code like

Greenhorn
Posts: 6
Thanks! I have tried this before, but it was giving me that 'there is no need for an If statement in this exercise. it says write an expression only. says no semicolons either. will you be able to stil help?

Henry Wong
author
Marshal
Posts: 21714
85
If "it" doesn't like the "if" statement, then don't use it. The "if" keyword was not part of the expression anyway.

Henry