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 trial
Paul Leenheer
Courses Plus Student 11,720 PointsUsing the console's printf method, display a message that says, "First name: ", followed by the first name that the user
Using the console's printf method, display a message that says, "First name: ", followed by the first name that the user has entered. Task 3:
// I have imported java.io.Console for you. It is a variable called console.
String firstName=("first name");
String lastName=("last name");
console.readLine("%s", firstName);
console.readLine("%s", lastName);
console.printf("First name:%s", firstName);
This is my code but i don't get what i am doing wrong here. The code seems right to me?
i get this error the whole time: Bummer! Did you forget to pass the firstName parameter to the printf function?
Nevermind here is the answer:
String firstName=("first name");
String lastName=("last name");
firstName = console.readLine("%s", firstName);
lastName = console.readLine("%s", lastName);
console.printf("First name:%s", firstName);
1 Answer
eren
503 PointsI'm also stuck on this exact question. Please help!
Joseph Wasden Here's the link: https://teamtreehouse.com/library/java-basics/getting-started-with-java/io
Edited: Paul, I tried your answer and it worked, but I'm still not sure how it worked... :/
Joseph Wasden
20,407 PointsHI eren, I'd be happy to help, but what are you stuck on? I'd probably encourage you to write your own question, if it is different than the above one.
Paul's original issue seems to have been that he had forgotten to assign the result of his console.readLine() to the firstName and lastName variables. Once he did that, the printf function could read the proper value in the variable.
If you've got more questions, feel free to ask.
Joseph Wasden
20,407 PointsJoseph Wasden
20,407 PointsCould you include a link the the challenge in question?