*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "printf() method clarification required" Watch "printf() method clarification required" New topic
Author

printf() method clarification required

M Kothawade
Greenhorn

Joined: Dec 29, 2008
Posts: 9
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

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.


SCJP 6
M Kothawade
Greenhorn

Joined: Dec 29, 2008
Posts: 9
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.
 
 
subject: printf() method clarification required
 
Similar Threads
why does this print true?
Formatting %s,%b
problem with array
K&B book, page 503 q9
Question 9, Chapter 6 in K&B