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

Pam Russell
Pam Russell
675 Points

How to store a users last name using console.readline

I am trying to do question 2 of the challenge and cannot find out how to store a users last name using console.readline. I got the first name right but not the second. Watched the video again and cannot figure it out.

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("What is your name?  ");
String firstName = console.readline("What is your name?  ");

3 Answers

Also, I think the console.readline is case sensitive. It should be console.readLine(""); With a capital "L"

Hi Pam Russell,

without looking at the exercise and see what exactly is expected for you to do, I can see that you overwrite the firstNamevariable in the second line. Try to change the second variable name to lastName.

Did this fix your problem already?

Santiago Martinez
Santiago Martinez
5,764 Points

I agree with Mario, just rename the second variable. You have two firstName so when you are storing the first input it will store what you type but than you will have to type again and it will store it in firstName which will override it

String firstName = console.readLine("What is your first name? "); String lastName = console.readline("What is your last name? ");