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 trialjohnacosta
275 PointsUsing the console's printf method, display a message that says, "First name: ", followed by th
I don't know what i am doing wrong here. Please help
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("John");
String lastName = console.readLine("Acosta");
console.printf("First Name, %s");
3 Answers
Mihai Craciun
13,520 PointsWhen you use any .printf() method you should use the exact number of arguments that you specified in the first argument
console.printf("First Name: %s", firstName);
//because you used %s that means the method expects one String argument
Lets say we have more arguments...How about 3:
console.printf("Hello %s, my name is %s and I am %d years old", yourName, myName, myAge);
//now the method expects 3 arguments %s means it expect a string and %d a number value
//in order you should give the method the arguments it expects by your signature ("%s%s%d")
//and separated by a comma
af09
10,704 Pointstry this:
console.printf("First Name: %s", firstName);
johnacosta
275 Pointsthank you