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 My question about Format 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 "My question about Format" Watch "My question about Format" New topic

My question about Format

Maggie Zhou

Joined: Sep 09, 2008
Posts: 26
I have a question about the printf format

I thought the code will throw a exception, but the result is :
123 987.123450

why? I can not understand this

Preparing SCJP 6, try to get high score, and looking for a job...
Nikos Pougounias
Ranch Hand

Joined: Jan 16, 2008
Posts: 110
%2d means: Format an integer and display it with at least 2 characters.

%1f means: Format a floating point and display it with at least 1 character.

An exception would be raised if you switched the arguments: %2$d %1$f

Try it for your self!

Format string syntax
[ September 13, 2008: Message edited by: Nikos Pugunias ]

Nikos' Java blog
Maggie Zhou

Joined: Sep 09, 2008
Posts: 26
Thanks a lot! Now I see
I agree. Here's the link:
subject: My question about Format
It's not a secret anymore!