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 trialIvan Perez
218 PointsDeclare 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?
// 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
Steve Hunter
57,712 PointsHi 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.
naman tiwari
773 PointsString firstName = console.readLine("naman");
Pedro Araya
1,912 PointsString firstName = "Steve". It is not necessary to put a name you can do it like this: String firstName;
Steve Hunter
57,712 PointsTrue. It was a year ago - I guess I'm forgiven.
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
12,002 PointsString 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.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsYep - you can do it over two lines and assign something to the variable initially:
The above works fine. I'm not saying you should do it that way but you can. ;-)