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 and Variables

Brady Cramer
Brady Cramer
659 Points

%s how does it know that firstName should replace it? is it because the printf hidden fuctions have %s inside the code?

I am confused on how it new for %s to be replaced by firstName. Is it because in the program we are using or language (still new), it is already a command inside of printf that when %s is used it will appear as what you put after a comma?

sorry if that is not clear. I am just confused on how it was able to do that without us telling it to replace %s with firstName.

1 Answer

Well, the printf method takes a format string and some values. A formatted string is one that has formatting in it (instead of the normal strings). And the %s is a tells printf to insert a string there. And since firstName is a string, it works.

See printf docs here: https://docs.oracle.com/javase/8/docs/api/java/io/PrintWriter.html