Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Getting Started with Java IO

Eitay Zilbershmidet
Eitay Zilbershmidet
3,942 Points

Why does this Java code resolve the challenge?

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

// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("First name:  ");
String lastName = console.readLine("Last name:  ");
console.printf("%s", firstName);

Tnx

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine();
String lastName = console.readLine();
console.printf("%s", firstName);

2 Answers

Hi there,

When I tried your code, it didn't pass the challenge. This is because the compiler is expecting a certain output string which your code doesn't quite match.

You've asked the user to input their first and last names via standard input, and stored those two strings in suitable variables. Let's assume firstName holds the value "Steve" after that. You are then trying to output the string "First name: Steve".

Your last line of code needs to add the filler text, "First name: " to pass the challenge, then insert the string into the end of the string. Something like this:

String firstName = console.readLine("Enter your first name: ");
String lastName = console.readLine("Enter your last name: ");
console.printf("First name: %s", firstName); 

I hope that helps.

Steve.

Eitay Zilbershmidet
Eitay Zilbershmidet
3,942 Points

Hi Steve,

Thank you for the quick replay. Just got it now :)

Thank you again Eitay

No problem - glad you got it sorted.

Steve.