This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes return boolean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "return boolean" Watch "return boolean" New topic
Author

return boolean

john mor
Greenhorn

Joined: Mar 06, 2005
Posts: 11
Hi!
I have a little problem.

Hector Tenedero
Ranch Hand

Joined: Oct 13, 2008
Posts: 31
Either you do it using logical operators or simply return true or false. But declaring a variable that will hold boolean values and manipulating it on whether or not it satisfies the condition would be the best option ( I guess )

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Disagree. Look in the Sun code conventions section 10.5.2 and you see that format is discouraged.

You should writeAs for printing out a boolean (or a Boolean) the PrintStream (= System.out.).print and println methods are overloaded to take a boolean argument.

If you prefer the printf methods (which you ought to use whenever possible) you find the %b tag will print a boolean as true or false. You can also use the %B tag which prints TRUE or FALSE! You can find a bit about printf in the Java Tutorials, and there is more detail (but less easy to read) in the Formatter class.
Hector Tenedero
Ranch Hand

Joined: Oct 13, 2008
Posts: 31
Thanks for the correction Ritchie . He can then just add additional equal() methods in the condition.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
You mean add more boolean values with && or || operators. Of course. What you are returning is (the result of) a plain simple boolean expression.

Obviously if the expression gets long, you would be better to have named boolean variables and put them together with operators, otherwise the expression will become incomprehensible.
 
GeeCON Prague 2014
 
subject: return boolean