wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes printf() method clarification required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "printf() method clarification required" Watch "printf() method clarification required" New topic

printf() method clarification required

M Kothawade

Joined: Dec 29, 2008
Posts: 9
System.out.printf("%d", 12.3);
throws exception.

System.out.printf("%b", 12.3); doesn't throw any exception.
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
%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

Joined: Dec 29, 2008
Posts: 9
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.
It is sorta covered in the JavaRanch Style Guide.
subject: printf() method clarification required