This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes boolean quiz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boolean quiz" Watch "boolean quiz" New topic
Author

boolean quiz

Ade Fapetu
Greenhorn

Joined: Oct 09, 2005
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

OK, tell us your answer, and we'll tell you if it's right.


[Jess in Action][AskingGoodQuestions]
Ade Fapetu
Greenhorn

Joined: Oct 09, 2005
Posts: 6
x<=0 is 1
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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?
Ade Fapetu
Greenhorn

Joined: Oct 09, 2005
Posts: 6
(x == 0)is true
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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

Ade Fapetu
Greenhorn

Joined: Oct 09, 2005
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
Sheriff

Joined: Sep 28, 2004
Posts: 18754
    
  40

If "it" doesn't like the "if" statement, then don't use it. The "if" keyword was not part of the expression anyway.



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
 
subject: boolean quiz