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 Java Basics Getting Started with Java IO

Rampant Developer
Rampant Developer
2,784 Points

I don't understand how this line is wrong: console.printf("First name: %s", firstName);

the code checker keeps asking if I forgot to pass the firstName to the printf function, which I haven't. I don't know how to solve this code challenge.

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = "";
String lastName = "";
console.readLine(firstName);
console.readLine(lastName);
console.printf("First name: %s", firstName);

2 Answers

Nikos Tzouvelekis
Nikos Tzouvelekis
8,155 Points

Hi :) That's the correct answer :

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

and that's why : you have a String but is empty so you must get a value from the user ... at console.readLine( "here goes the message for user ... example : enter your name " );

so the line isn't wrong but the value of String firstName it's null and this is wrong

with tis way :

firstName = console.readLine();

you pass at this string the value that user write

check out again the last video :)

Rampant Developer
Rampant Developer
2,784 Points

that did the trick. Thank you very much for the help!