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

johnacosta
johnacosta
275 Points

Using 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

IO.java
// 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
Mihai Craciun
13,520 Points

When 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

try this:

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