Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printf() method clarification required

 
M Kothawade
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why
System.out.printf("%d", 12.3);
throws exception.

whereas
System.out.printf("%b", 12.3); doesn't throw any exception.
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
%b and %s will never throw exception in these types of case.

for %b if you pass null, boolean false or Boolean false then it will print false, otherwise for any values it will print true.
 
M Kothawade
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I went through http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html and got the same answer.

Thanks once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic