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

Using the console's printf method, display a message that says, "Last name: " Java basics challenge 4/4

i cannot figure out what is wrong with this code.

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?  ");
console.printf("my name is %s\n",firstName);
String lastName = console.readLine("What is your last name?  ");
console.printf("first name: %s\n",firstName);
console.printf("last name: %s\n",lastName);

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Matthew,

Although you have no syntax errors, your answer really doesn't satisfy what the challenge is specifically asking for.

  • First, it's a real good practice to keep you code in the order of what the Tasks are asking (unless specifically told otherwise. Eg. Task One: wants first name variable and Task Two: wants last name variable, so the last name one should be directly under the first name one.

  • Second, Challenge are very picky and very strict in what they ask for and what they check for. These tasks want your to print the string "First Name: " with both a capital "F" and and "Capital "N"... same thing with "Last Name: " (Capital "L" and Capital "N"

  • Third, none of the 4 tasks asked for the line "My name is....", so that needs to be deleted.

Below is the corrected code for your review. Please have a look over and make sure it makes sense.

// 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: %s\n", firstName);
console.printf("Last Name: %s\n", lastName);

Keep Coding! :) :dizzy: