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

Im not understanding what it's asking?

it says to Now replace <YOUR NAME> in the console.printf expression with the firstName variable using the string formatter. I have no clue what that means. I dont know what a string formatter is. They pretty much blew threw the video without talking about it

Name.java
// I have setup a java.io.Console object for you named console
String firstName = "Robbo";
console.printf("<firstName> can code in java!\n");

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

printf() allows you to put placeholders in the string for other variables that are also passed into printf after the string. These placeholders start with a percent sign (%) and have their own special syntax. You don't need to worry about all the details just yet, just that %s means "substitute a string". The placeholders will be substituted in order, with the first substituted with the first variable that follows, etc. So to insert the variable firstName into the output your you write:

console.printf("%s can code in java!\n", firstName);

console.printf("Hello, my name is %s\n", firstName);

This was how we wrote in the beginning. So i was confused and did not realize that works in general. I thought it had to be in that format. Thanks Seth!