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 trialLajos Rácz
163 Pointsprint your own name with printf. ErrorMessage: Check the spelling of your argument to the printf method. Make sure it
Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!"
String firstName = "Lajos"; console.printf("Hello name is %s\n", firstName);
or
console.printf("<Lajos>");
or console.printf("Lajos");
Bummer! Check the spelling of your argument to the printf method. Make sure it is printing out what the instructions are asking for.
// I have setup a java.io.Console object for you named console
String firstName = "Lajos";
console.printf("Lajos");
2 Answers
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi Lajos,
You're not printing out the value of the variable. You need to create a string that includes the first name variable and some text. To do this you need to include the value in your printf method.
This is how it works.
// I have setup a java.io.Console object for you named console
String firstName = "Lajos";
console.printf("%s can code in Java!", firstName);
So first of all you declare a variable with the String data type as you did before. So your name is the value of that variable.
Then you use the conssoles printf method to display that value with the rest of your string. The way you pass in your name as part of the string is with something called a format specifier. You match the value with the name of the vatriable like it is a function argument.
console.printf("%s can code in Java!", firstName);
Hope this helps :)
Lajos Rácz
163 PointsThank you.