• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return boolean

 
john mor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I have a little problem.

 
Hector Tenedero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the correction Ritchie . He can then just add additional equal() methods in the condition.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic