• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sytstem.out.format

 
Mrinal Singhania
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



The first line prints "true", while the second throws an exception. I don't understand why? AFAIK, booleans are not equivalent to ints/doubles, in that true != 1 and false != 0 in java.

Can someone please explain.

Thanks.
 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the javadoc for the java.util.Formatter class, particularly the chart about the behavior for each type.

'b', 'B'
general
If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".


Henry
 
Mrinal Singhania
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:Take a look at the javadoc for the java.util.Formatter class, particularly the chart about the behavior for each type.

'b', 'B'
general
If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".


Henry


Hi Henry,

Thanks for the reply. And this solves my problem

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic