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

AR Ehsan
AR Ehsan
7,912 Points

Challenge 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!

IO.java
// I have imported java.io.Console for you.  It is a variable called console.

9 Answers

Josip Dorvak
Josip Dorvak
18,126 Points

I'm on my phone and not 100% sure on the syntax, but it will look something like this:

String name = console.readLine();
AR Ehsan
AR Ehsan
7,912 Points

That is wrong! I tried it.

Josip Dorvak
Josip Dorvak
18,126 Points

Also adding a string as a parameter will act as a prompt for a User:

console.readLine("What is your name?");
Josip Dorvak
Josip Dorvak
18,126 Points

Maybe the question only asks to add a variable...in that case just have:

String name;
AR Ehsan
AR Ehsan
7,912 Points

Can you please exactly tell me what I have to do!

Josip Dorvak
Josip Dorvak
18,126 Points

My 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
AR Ehsan
7,912 Points

That is wrong too

AR Ehsan
AR Ehsan
7,912 Points

Can you give me an answer for task 1 2 3 and 4. Thanks!

AR Ehsan
AR Ehsan
7,912 Points

Are you still there

Josip Dorvak
Josip Dorvak
18,126 Points

Not near a computer and it's been awhile since I did this....so for the exact answer, I can't help

Josip Dorvak
Josip Dorvak
18,126 Points

It could also be a problem with treehouse itself

Try this:

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

This 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
AR Ehsan
7,912 Points

Hi! ISAIAH S. For step 2 3 4 could you help me! It didn't work. The code.

AR Ehsan
AR Ehsan
7,912 Points

Hi! ISAIAH S. For step 2 3 4 could you help me! It didn't work. The code.

1:

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);