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 trialUnsubscribed User
800 PointsAdd a variable to store a userβs first name using console.readLine. Make sure the variable is the camel cased representa
it keeps telling me to use camelCased and it is. what am i doing wrong
// I have imported java.io.Console for you. It is a variable called console.
console.readLine("firstName ");
2 Answers
Steve Hunter
57,712 PointsAs Dan says, you need to store a name in a variable named with camelCase convention.
So, you're storing a string, so it shoud be delcared as such and this string will hold the input of the console.readLine
command.
Something like:
String firstName = console.readLine("Dave");
The value "Dave" will then be stored in firstName
.
Dan Johnson
40,533 PointsThe string passed into readLine is the prompt to the user. The return value from readLine is what contains the input and what you'll want to set a String variable (with the name of firstName as you had) to.
Dan Johnson
40,533 PointsDan Johnson
40,533 PointsIf you were to call
String firstName = console.readLine("Dave");
This will present the user with the text "Dave" before their input. firstName will contain whatever was typed in after the prompt, and before a newline was encountered.
Oracle docs: http://docs.oracle.com/javase/7/docs/api/java/io/Console.html#readLine%28java.lang.String,%20java.lang.Object...%29
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsSorry, I'm talking nonsense - Dan, thankfully, isn't!! :-)
Dan Johnson
40,533 PointsDan Johnson
40,533 PointsNo worries, just didn't want any confusion over the String argument.