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 trialkunal grover
39 PointsUsing the console's printf method, display a message that says, "First name: ", followed by the first name that the user
confused what i am doing wrong
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine ("kunal");
String lastName = console.readLine ("Grover");
Console.printf("%s\n,first name");
1 Answer
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 PointsHello Kunal,
You are very close.
The message that is printed to the console is the format string, it is the first parameter that is passed to printf. That string needs to output "First Name: Kunal". I think you might have gotten confused because you did not realize that "First Name:" needed to be part of the format string.
The variable, firstName, is the second parameter passed to printf, and it will replace the format specifier %s in the format string.
Notice how the 2 parameters passed to printf in parenthesis, the format string and the variable, are separated by commas.
Notice how the format string is surrounded by quotes but the variable, firstName is not.
console.printf("First name: %s\n", firstName);
This video goes over all these concepts: https://teamtreehouse.com/library/strings-and-variables
Happy Coding! Heidi
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 PointsHeidi Fryzell
Front End Web Development Treehouse Moderator 25,178 PointsHello again Kunal,
One more thing I noticed.
When you are calling the readLine method, the text in the quotations should be the question you are asking the user. You put your name in the quotations, but it is the user's answer that will get assigned to the string variable when they enter something into the prompt.
Hope that helps clarify. Heidi