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

Console.printf

What does it mean to pass the firstName parameter to the printf function? I am confused why my line 5 and 6 are not working

IO.java
String firstName = "Mave";
console.readLine ("%s", firstName);
String lastName = "Haimbodi";
console.readLine ("%s", lastName);
firstName = console.readLine ("First name:");
console.printf ("First name: %s", firstName);

// I have imported java.io.Console for you.  It is a variable called console.

1 Answer

Simon Coates
Simon Coates
8,481 Points

You have a couple lines that are a bit weird. If calling readline, you need to provide prompts containing information about the value you want back. Additionally, the point of calling readLine is that it returns a value. However, I think the message it's giving you is probably a flaw in their challenge verification code. For the record, it accepts:

// 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 ("First name: %s", firstName);
console.printf ("Last name: %s", lastName);

You'll note that the line to output the first name is the same as in your code. (so implicitly, if the line it thinks is wrong is correct, then it's tripping over something else)