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

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