Win a copy of Practical SVG this week in the HTML/CSS/JavaScript 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.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!