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

kelvin muniz - roque
kelvin muniz - roque
403 Points

console.printf("First name: %s", firstName); i cant see the error. claims i forgot the firstName parameter

can anyone help me. i tried sticking to the format i am learning. i cant see where i am wrong.

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

1 Answer

Steven Parker
Steven Parker
229,732 Points

The instructions asked for the first and last names to be stored in the new variables using "console.readLine", but the code here is storing fixed string literals instead. You do have some calls to "console.readLine", but the result is not being stored anywhere.

Apparently the challenge got confused and passed your previous tasks anyway, but on this one it's actually looking for the input it provides to be there and not finding it.

You'll need to start over and redo tasks 1 and 2 without using the string literals.

kelvin muniz - roque
kelvin muniz - roque
403 Points

i think i understand and i have another solution that led me to the same error i am having a. here is my new code that seems better but still incorrect.

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

i might be misunderstanding the video tutorial that teaches this challenge.

Steven Parker
Steven Parker
229,732 Points

You still need to get rid of the string literals, and assign the result of calling the method. Also, the "readLine" method does not take any parameters.

So the first line should look like this:

String firstName = console.readLine();