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

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.