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

Gustavo Borges
Gustavo Borges
309 Points

I cant pass this exercise!

In my perspective, I'm not doing anything wrong.

But this message keeps coming, every time I ask to check my work: "Did you forget to pass the lastName parameter to the printf function?"

I think I a;ready passed the lastName parameter to the printf function, right?

Could someone help me?!

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("What is your first name?  ");
String lastName = console.readLine("What is your last name?  ");

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

console.printf("Last name: ", lastName); 
console.printf("%s", lastName);
Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Your code is almost fine, but the environment is complaining because two lines are missing the string formatters.

3 Answers

Gustavo Borges
Gustavo Borges
309 Points

Thanks a lot!

That's weird... because before the lastName step, I used two lines (as you could in my code) and it worked.

Once I tried to do the same thing in the last step, the system didn't allow me to finish it.

But I understand your point!

Again, thanks a lot!!!

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Gustavo,

look at my code suggestion. I added just a few modifications.

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

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

Grigorij

David Lacedonia
David Lacedonia
13,627 Points

This works:

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

Don't pass any parameter when you dont have %s.

If you want the printf methods in diferent lines, also you can do...

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