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

Declare a variable that is named the camel-cased version of "first name". Store the user's first name into this new vari

Declare a variable that is named the camel-cased version of "first name". Store the user's first name into this new variable using console.readLine.

still having an issue with this set up. what am I doing wrong?

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

3 Answers

Hi there,

You only need to declare a variable once - so your second String isn't needed, the compiler knows firstName is a String from the first time you told it.

Second, I'm not sure the compiler is expecting you to assign something to the variable, then read in the user's input. (I'll try it in a sec)

So, you can do all this in one line:

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

Will edit in a sec when I've tried your way

Steve.

Yep - you can do it over two lines and assign something to the variable initially:

String firstName = "Steve";
firstName = console.readLine("Enter name: "); // omit second String

The above works fine. I'm not saying you should do it that way but you can. ;-)

naman tiwari
naman tiwari
773 Points

String firstName = console.readLine("naman");

Pedro Araya
Pedro Araya
1,912 Points

String firstName = "Steve". It is not necessary to put a name you can do it like this: String firstName;

True. It was a year ago - I guess I'm forgiven. :wink:

However, I was making the point, as per the question asked, that it is ok to assign something to the variable before storing user input in there. It was a deliberate check to see what would work in an attempt to answer the question fully.

Steve.

Jeremy Kerrigan
Jeremy Kerrigan
12,002 Points

String firstName = console.readLine();

It is only asking you to create a variable that will store the users first name. You do not need to put anything between the parentheses yet. The question hasn't asked that of you yet.