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 trialJames Young
775 PointsPrint out to the screen using the printf method on console, "First name: " and the user's first name.
Hey guys can someone please help me out, I have no clue what I am doing wrong. Any feed back would be awesome! Thank you
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("firstName");
String lastName = console.readLine("lastName");
"console.printf"("%s",firstName);
2 Answers
Richard Ling
8,522 PointsHi James,
Your code is very nearly correct - the 3rd line doesn't need the quotes around console.printf. The quotes indicate a literal string value so the contents won't be interpreted as instructions. You will also need the text "First name: " as part of what you output to the screen. This gives you:
String firstName = console.readLine("firstName");
String lastName = console.readLine("lastName");
console.printf("First name: %s",firstName);
This should work just fine. Adding the last name part should be just the same format.
This isn't an error at all, but just so you are aware - where you used the readLine methods, in the quotes you have used firstName and lastName, just like the variables name themselves. This text in quotes doesn't have to be the same as your variables names - this is what will be displayed to the user as the on screen prompt when asking for input.
So for example, on the course, they use something like:
String firstName = console.readLine("What is your first name? ");
With the 2 spaces at the end of the question, so that the text the user types will be away from the end of the sentence, and is a little more pleasing to the eye.
I hope this helps, but shout if not :)
Thanks, Rich
James Young
775 PointsI appreciate the great response! Thank you for taking time out of your day to help me out! Have a good one!!
Unsubscribed User
12,721 PointsHey James, I figure you are new to Treehouse.
A suggestion -> you can add comments to the answers and do not need to post seperate answers for the same. You can even upvote Richard Ling 's answer. This should help the community if a thread becomes large and people need to figure out which answer is the most accepted.
MUZ140567 Merceline Nhamo
4,739 PointsMUZ140567 Merceline Nhamo
4,739 PointsI tried but I
m being told that I forgot to pass the
firstName` parameter to printf function