File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes formatting conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "formatting conversion" Watch "formatting conversion" New topic

formatting conversion

sentil kumar
Ranch Hand

Joined: Oct 23, 2006
Posts: 74
System.out.printf("%s",new Float(11)); - prints 11.0
System.out.printf("%d",new Float(11));
throw java.util.IllegalFormatConversionException: d != java.lang.Float.

first printf statement implies that (String) s == java.lang.Integer
how the first prinf statement runs fine.
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
The Format string syntax API documentation says this about %s

Conversion: 's', 'S'
Argument Category: general
Description: If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().

Float doesn't appear to implement Formattable, but it has a toString() method.
[ November 23, 2006: Message edited by: Carol Enderlin ]
I agree. Here's the link:
subject: formatting conversion
Similar Threads
Question 9, Chapter 6 in K&B
format query
Date API