Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

boolean quiz

 
Ade Fapetu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, tell us your answer, and we'll tell you if it's right.
 
Ade Fapetu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
x<=0 is 1
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(x == 0)is true
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20902
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If "it" doesn't like the "if" statement, then don't use it. The "if" keyword was not part of the expression anyway.



Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic