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 trialLeong Lee
52 PointsI need help, I need to know what i am doing wrong it is asking for %s?
Need help with one of the challenges
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
Faraz Malik
20,721 PointsYou'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);
Eric Queen
13,214 PointsHello 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!
Eric Queen
13,214 PointsEric Queen
13,214 PointsFor 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.