Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Getting Started with Java IO

help me solve this Print out to the screen using the printf method on console, "Last name: " and the user's last name.

I didn't able to solve this quiestion :

Print out to the screen using the printf method on console, "Last name: " and the user's last name.

it was my stage 1 ,Getting started with Java challenge Task 4 of 4

IO.java
// I have imported java.io.Console for you.  It is a variable called console.

String firstName = console.readLine(" your last name is :" );

String lastName = console.readLine(" Last name : ");

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

2 Answers

Sometimes these exercises want very precise answers. It looks like you're adding extras to your answers. When I did the exercise, it only wanted first name in a variable, and last name in a variable, then asked to print a line with each variable.

String firstName = console.readLine("First name: ");
String lastName = console.readLine("Last name: ");

// I think this is where the issue is... Watch the formatting and only add what it's asking for.

console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);
Dylan Malzinskas
Dylan Malzinskas
2,028 Points

It is also useful and a good habit to add a "\n" inside the quotations of the printf function as this will allow the console to continue to print on the next line in the console screen. If the question didnt ask for printf then println would have been a good choice to use also

Thanks a lot Tod Novak . I will do like that ..!!

Thanks a lot Novak