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

Michael Wheeler
Michael Wheeler
1,036 Points

Using 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.

IO.java
// 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("First name: %s", firtName);

1 Answer

You have mis-spelled the firstName variable in the printf function as firtName.

However, I am not sure if your code will pass after you fix this error. The way you have coded the first two parts of the challenge have resulted in you storing an empty string in both the firstName and lastName variables and you will therefore get an empty string as your firstName value in the printf function.

I believe that the proper way to code the first two parts of the challenge are as follows:

String firstName = console.readLine();
String lastName = console.readLine();

If coded this way, the tester will (presumably) provide a name value to be read into the firstName and lastName variables when it attempts to test your code.