This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Printf question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Printf question" Watch "Printf question" New topic
Author

Printf question

Anu Bhagat
Ranch Hand

Joined: Jun 20, 2008
Posts: 64
Hi ,
The following code prints
1213%1$s

I understand the 1213 portion of the output, but don't undersatnd the rest of the output. Please expain. I read the Java Language documentation but don't get it.

Thanks in advance.
Anu



SCJP5.0, SCJA
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Anu,

There is only a format string in the call: "12%1$s". This simply constructs a string with the contents "12" plus the first argument in the argument list using string conversion (basically, creates a string which is "12" concatenated with the second argument of the printf() call.)


All code in my posts, unless a source is explicitly mentioned, is my own.
 
jQuery in Action, 2nd edition
 
subject: Printf question