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

I need help, I need to know what i am doing wrong it is asking for %s?

Need help with one of the challenges

IO.java
String firstName = console.readLine("What is your first name?  ");
String lastName = console.readLine("What is your last name?  ");
console.printf("First name:", firstName);

2 Answers

You're supposed to place a %s at the last line to give a reference for where you are going to input the variable. The statement for printing out was also incorrect. It's like this:

System.out.printf("Firstname: %s", firstName);

For this Code Challenge System.out has already been imported and placed into a variable named "console". This is from the challenge:

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

Hello Leong, Seems like you forgot something, the %s. That is why it is prompting you for it. The printf() method takes in an argument, which you have by the way of "firstName". Because firstName is of String type you need to tell printf() where in the output string you want it to be placed with the %s. Your code should look like this:

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

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

I have also added the %n to tell the console to move to a new line after it finishes printing the text. Otherwise your prompt will be on the same line after the firstName.

Hope this helps and good luck!