Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printf question

 
Anu Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic