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 trialKhanh Dao
641 PointsWhat does "Make sure that you use the `firstName` variable as the second argument" means?
The question is "Now replace <YOUR NAME> in the console.printf expression with the firstName variable using the string formatter." I dont get what this means.
// I have setup a java.io.Console object for you named console
String firstName = "Khanh";
console.printf(" %s can code in Java!", firstName);
Paul Ownby
23,414 PointsWhen using printf, you can use string formatters to create a template for what is going to be displayed and then send in variables after the template that are used to fill in the template.
In the example above, your string has %s in the template which tells printf that you will follow the template with a string - either a variable like firstName or an actual string like "Paul". If you have multiple formatters like %s and %s as follows :
console.printf("%s is my first name and %s is my favorite color", firstName, favoriteColor);
the first variable, firstName, is used in place of the first %s and the second, favoriteColor, for the second so that the result is:
"Paul is my first name and orange is my favorite color" if firstName = "Paul" and favoriteColor = "orange"
In your code above, the first argument for printf is the string template and the second argument is firstName. In my example, the first argument is the string template and the second argument is firstName and the third argument is favoriteColor.
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're doing great, and the Bummer! message you're receiving is a little misleading. It's indicating that you aren't passing in the firstName variable as the second argument, but you are. The first argument is the string we're formatting. But there's a problem with your string. It contains a couple of extra spaces, so it's not getting back the string it's expecting. Take a look:
//Your code
console.printf(" %s can code in Java!", firstName);
//Passing code
console.printf("%s can code in Java!", firstName);
Your "%s" has one extra space on both sides. If I correct this, your code passes!
Hope this helps!
Andrei Cioloca
Courses Plus Student 17,680 PointsAndrei Cioloca
Courses Plus Student 17,680 PointsYou have to press "Check Work " :))) and that's it.