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

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.