Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPedro Silva
5,363 PointsI got a little lost, what exactly "%s" is and do?
i understand how to use "%s" in this exercise but not what it is and if this is it's only use, can anyone help me?
1 Answer
Steve Hunter
57,712 PointsHi Pedro,
It's a placeholder for a string, so at that point within the output string, the java code will insert the contents of a variable which you place after the output string.
String name = "Steve";
console.printf("Insert my name here: %s.", name);
There are other types of placeholders for different data types, so there's different letters for numbers Some details here.
Steve.
Pedro Silva
5,363 PointsPedro Silva
5,363 Pointsoh i see, but just for curiosity, if i put a second variable after "name" from your example, he will always choose the first one? and if i put another "%s" on my sentence, it will follow the order the variables were written?
Thanks for the help Steve!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsYou can do as many placeholders as you like, yes. Then list the variable names in the order you want them to appear: