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

Jonathan Jimenez
Jonathan Jimenez
1,096 Points

Using the printf method, display a message that says, "Last name: " followed by the last name that the user entered

Using the console's printf method, display a message that says, "Last name: " followed by the last name that the user has entered. please help!

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("camel-cased");
console.readLine("firstName");
String lastName = console.readLine("camel-cased");
console.readLine("lastName");
console.readLine("First name: ");
console.printf("First name: %s", firstName);
console.readLine("Last name: ");
console.printf("Last name: %s \n", lastName);

1 Answer

Joel Price
Joel Price
13,711 Points

Hey man, It looks like you've got a bunch of extra code in here. Try something like this:

// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine();
String lastName = console.readLine();

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

This should read the lines, then store them directly to their respective variables, firstName and lastName. Then you just print them off one right after the other. You can get fancier with it if you wanted to, but as for what the challenge is looking for, this is about all that's required.

Jonathan Jimenez
Jonathan Jimenez
1,096 Points

Hey Joel, so i tried to clean it up like you said, it informed me that task 3 is no longer correct so that means that the challenge is meant to get bigger my problem right now is how to distinguish each string. i don't think i could use %s to access both lastName and firstName because i followed your steps and it didnt work