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

Beh Jiunn
Beh Jiunn
251 Points

IO challenge Task 3 of 4

I've indicated the line console.printf("First name: %s", firstName); but it still shows errors.

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

2 Answers

Hi there,

This is a strange one. Your code is fine. However, the tests are complaining about the order you have your first two lines of code in. If you switch them around, so declare firstName first, your code will pass.

String firstName = console.readLine("What is your name");
String lastName = console.readLine("What is your last name");

console.printf("First name: %s", firstName);

I don't know why this is.

Steve.

Beh Jiunn
Beh Jiunn
251 Points

Technically it should work fine right? Thanks for the feedback!! :)

Yes. It should work, as far as I am aware. I see no reason that the order of those two variables affects their use downstream of that point.

Maybe you should try to replace this line <<console.printf("First name: %s", firstName);">> by this one <<console.printf("First name: %s , Lastname : %s", firstName,lastName);>> I am not very sure but I think that since you declared two variables, maybe the java compiler is expecting two variables.