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

David Reid
David Reid
2,082 Points

Stuck on "Print out to the screen using the printf method on console, "First name: " and the user's first name."

I keep getting the error that says make sure to use the first name variable, but I believe I did in the last line of code there.

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
Print out to the screen using the printf method on console, "First name: " and the user's first name.
String firstName = console.readLine ("what is your first name");
String lastName = console.readLine ("What is your last name");
console.printf("%s\n", firstName);

3 Answers

Seth Kroger
Seth Kroger
56,413 Points

You need to print "First name: " before the name. Also the 2nd line should be commented out with 2 forward slashes since it's not Java code.

David Reid
David Reid
2,082 Points

I finally got, it took a little bit but this helped. Thank you very much!

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Try it this way :

//here you store the user input in the String firstName
String firstName = console.readLine ("what is your first name ");

//here you use the printf method from the console class to print the users input (firstName) for the format %s
console.printf("Your first name is %s\n ", firstName);

Hope it helps :)

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey keep on descovering ... we are all beginners in some way, somewhere...