aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes printf confusion 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 confusion" Watch "printf confusion" New topic
Author

printf confusion

Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
i can't seem to get the hang of printf. how did you guys memorize all the combinations?

Also



...do we always need to have d in the end?






omnipresent
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

following are the characters those are required for outputting specific type of values
d for integers
b for booleans
s for strings
c for character and
f for float

and yes we have to give those character for respective values because the compiler gives error at runtime

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Michael Hilgert
Greenhorn

Joined: Apr 23, 2010
Posts: 17
Yes, that's right.
First have a look to the easiest printf.
All what you need is a % and a letter described above.


or


Then you can add other signs.

Do you want to have less digits after the dot, use

and so on
$1 : use the first parameter

You're welcome.
SCJP 6, SCWCD 5
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1717
    
  25

You can check the API documentation:
Java5API
and choose the class java.io.PrintStream.printf(String format, Object... args)
If you have read that, go further on the format section: format string format
Regards,
Frits
 
wood burning stoves
 
subject: printf confusion