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

Java

Angie Rodriguez
Angie Rodriguez
410 Points

"First name: " io java. I swear my code looks correct, but I keep getting an error message. What am I doing wrong?

I do not understand what else I need to do to move past this exercise. I reviewed the video, and matched the syntax to the instructor's. Why isn't this code working?

I keep getting this error:

Bummer: Did you forget to pass the firstName parameter to the printf function?

My code looks like this:

String firstName = "Angie";
console.readLine(firstName);
String lastName = "Rodriguez";
console.readLine(lastName);
console.printf("First name: %s", firstName);

2 Answers

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,512 Points

Hi @Angie Rodriguez . Remember to always ask your questions from the question or video (by pressing the "Get Help" button) so others can easily look at the video or question. I included the link here for others.

So the short answer is nothing is wrong with your printf but with your readLine. The answer checker should not have passed your first exercise. Remember the readLine method returns the user input. So you have to set a variable = to the readLine. Like this:

String firstName = console.readLine();

While not required for this exercise but inside the () for readLine you put a message to the user. So in a real example you would want to put something like

String firstName = console.readLine("Please Enter your first name: ");

But i would not suggest doing that here since adding extra code sometimes confuses the checker. I just thought that explaining that would make it more clear how the readLine works.

Keep at it Angie Rodriguez and good luck!

Angie Rodriguez
Angie Rodriguez
410 Points

Thank you Mark, I realized my mistake after I submitted this question, but appreciate the detailed explanation.