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

I'm trying to display a message using the Printf method

I'm working on the Java basics code challenge -Task 4. I'm getting compiler and syntax errors. The task is to use the Printf method to display the message "Last name:" followed by the lastName parameter entered. Below is the code I've written.

String lastName = console.readLine("Garcia");

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

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

String firstName = console.readLine("Mikey");
String lastName = console.readLine("Garcia");

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

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

1 Answer

Hi Adolphus!

You are close. You just have a few errors on your printf statements.

You are supposed to do printf statements in one line. Like this:

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

and also do this for the last name

So you probably glitched through the third task, so when you make these changes it will probably say either task one or 3 is not passing so just retype those and you will finish the challenge in no time!

I hope this helps!

Here is the final code for task 4:

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

String firstName = console.readLine("Mikey");
String lastName = console.readLine("Garcia");

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

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

If it does not work please let me know.

Thanks! :)

Thank you Aayush for your prompt response. It worked.