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 trialAR Ehsan
7,912 PointsChallenge Task 1 of 4 Add a variable to store a userβs first name using console.readLine.
I tried everything I still don't know how to do it. Please help me.Thanks!
// I have imported java.io.Console for you. It is a variable called console.
9 Answers
Josip Dorvak
18,126 PointsI'm on my phone and not 100% sure on the syntax, but it will look something like this:
String name = console.readLine();
AR Ehsan
7,912 PointsCan you please exactly tell me what I have to do!
Josip Dorvak
18,126 PointsMy guess is right now the question is only asking you to declare a variable to hold input. So just have
String name;
As the answer
AR Ehsan
7,912 PointsThat is wrong too
AR Ehsan
7,912 PointsCan you give me an answer for task 1 2 3 and 4. Thanks!
AR Ehsan
7,912 PointsAre you still there
Josip Dorvak
18,126 PointsNot near a computer and it's been awhile since I did this....so for the exact answer, I can't help
Josip Dorvak
18,126 PointsIt could also be a problem with treehouse itself
Ryan Duchene
Courses Plus Student 46,022 PointsTry this:
String firstName = console.readLine("What is your first name?");
ISAIAH S
1,409 PointsThis might work:
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("First name: ");
console.printf("Hello, my name is %s.\n", firstName);
console.printf("%s is learning how to write java!\n", firstName);
Thanks!! ISAIAH S
AR Ehsan
7,912 PointsHi! ISAIAH S. For step 2 3 4 could you help me! It didn't work. The code.
AR Ehsan
7,912 PointsHi! ISAIAH S. For step 2 3 4 could you help me! It didn't work. The code.
ISAIAH S
1,409 Points1:
String firstName = console.readLine("your first name: ");
2:
String lastName = console.readLine("your last name: ");
3:
console.printf("First name: %s", firstName);
4:
console.printf("Last name: %s", lastName);
AR Ehsan
7,912 PointsAR Ehsan
7,912 PointsThat is wrong! I tried it.
Josip Dorvak
18,126 PointsJosip Dorvak
18,126 PointsAlso adding a string as a parameter will act as a prompt for a User:
console.readLine("What is your name?");
Josip Dorvak
18,126 PointsJosip Dorvak
18,126 PointsMaybe the question only asks to add a variable...in that case just have:
String name;