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 trialNicholas Sabbato
523 PointsWhat does "call the printf method on the console object" mean?
I have my String firstName = "Nick"; and now it is asking me to run my name. I can type it, but I don't know how to run what I typed out.
// I have setup a java.io.Console object for you named console
String firstName = "Nick";
console.printf("%s\n can code in Java!, firstName");
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! It's not actually asking you to run the code. The challenge will run your code for you. You have two problems in your code. One is a syntax error and one is a formatting error. You've put a new line character after your name which is not required by the challenge and will likely cause it to fail. Let's take a look at a similar example:
String favorite_food = "tacos";
console.printf("My favorite food is %s", favorite_food);
Because you've placed your closed quotations in the incorrect place, it now believes that "firstName" is not a variable but rather a part of the string literal, And because it's got the %s token in the string literal, it's still looking for a variable name. You must first end the string literal containing the string token, then add a comma, and finally the name of the variable. The %s will now be replaced with the value located inside the variable referenced.
As far as calling the printf method on the console object, that part you've done just fine (barring the syntax error). Hope this helps!
Philip Gales
15,193 PointsYou made your whole printf method a string. Here is how it should look, notice all I did was move the last quote to the end of the string (before the comma) and removed your new line \n.
// I have setup a java.io.Console object for you named console
String firstName = "Nick";
console.printf("%s can code in Java!", firstName); //<------------Edited this code
Nicholas Sabbato
523 PointsThanks
Nicholas Sabbato
523 PointsNicholas Sabbato
523 PointsThanks