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

Can anyone tell me what i am doing wrong here :S

I get an error message in this piece of code and i cant seem to see why.

The Task Using the console's printf method, display a message that says, "Last name: " followed by the last name that the user has entered.

The error message Bummer! Did you forget to pass the lastName parameter to the printf function?

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

1 Answer

Adnan Pozegić
Adnan Pozegić
12,789 Points

Try removing this line:

console.printf("hello, my name is  %s %s\n", firstName, lastName);

Tests are automated, I suppose the error is the result of not finding the output where it is expected, because you added this line, which wasn't required.

kelvin muniz - roque
kelvin muniz - roque
403 Points

String firstName = "mike"; String lastName = "shinoda"; console.readLine("lastName"); console.readLine("firstName"); console.printf("First name: %s", firstName);

these are the new lines i am using but i am still getting the error that i forgot the firstName parameter.

Adnan Pozegić
Adnan Pozegić
12,789 Points

Kelvin, try doing your tasks in the exact order and do not add anything else, also you are pointing the console.readLine() function to nothing. console.readLine() function returns the value you typed into the console, in your case it doesn't have any place to return that value to.