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 Please explain the output of this: This question is from ExamLabs Diagnostic Test 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 "Please explain the output of this: This question is from ExamLabs Diagnostic Test" Watch "Please explain the output of this: This question is from ExamLabs Diagnostic Test" New topic
Author

Please explain the output of this: This question is from ExamLabs Diagnostic Test

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174


output is 1213%1$s
Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
This is the signature for the method:

format is your first argument, args your second one. About your last argument printf doesn't care.
Also, your second argument, "13%1$s", is taken as a String. So "%1$s" is here not a placeholder
for anything.
What is done in the end? printf checks the first argument; prints 12, then gets the second argument and prints
13%1$s. Altogether: 1213%1$s

Hope that helps,
cheers
Bob


SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Aakash Goel
Ranch Hand

Joined: May 26, 2008
Posts: 198
Also (after you've read Bob's explaination), you can check out

printf (PrintStream)


SCJP 5 95%
SCJP FAQ | SCJP Mock Tests | SCJP Tipline | Generics
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please explain the output of this: This question is from ExamLabs Diagnostic Test