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 trial

Java Java Basics Getting Started with Java Strings, Variables, and Formatting

what does %s do

what does %s do

Name.java
// I have setup a java.io.Console object for you named console

String firstName = "Aryaman";
console.printf ("%s\n, can code in Java");

1 Answer

Think of %s as a placeholder.

When we make a string in Java, you can put these "magical" %s stuff in them.

You can use them in strings to refer to values you don't really know yet and in the future you can replace the %s stuff with a different string.

For example if I have the string "Hello %s. How do you do?" and I insert "Alex" into it Java will replace the %s with "Alex". Then the string would look like "Hello Alex. How do you do?".


It is also a good idea to review the Strings and Variables video at around time 04:21 and pay extra attention :)

I hope this helps. ~Alex