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

Tefo Temba Kebitseng
Tefo Temba Kebitseng
6,049 Points

Challenge Task 4 of 4 Using the console's printf method, display a message that says, "Last name: " followed by the l

I added the last line to the code which i thought would add the required message to be displayed like it happened with the first line.

now the error is that "i forgot to pass the lastName parameter"

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");
String lastName = console.readLine("What is your last name");
//camel-casing

console.printf("% is your name", firstName);
console.printf(" your name  is %\n", firstName);
console.printf("% is your last name", lastName);
console.printf(" your last name  is %\n",lastName);

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

It's important to note that in challenges you need to do exactly what they tell you to do and no more. Even if functional outside the challenge, it can cause the challenge to fail. If you remove the first four console.printf statements, your code passes! Hope this helps! :sparkles:

Tefo Temba Kebitseng
Tefo Temba Kebitseng
6,049 Points

Thank you Jennifer but it didn't help...it is nested question. The last line to display the last name gives an error that the value has not been passed whereas it got passed in the statement Line 2 ,second string declaration and assigning of the supplied input.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

That's really strange. Because if I take this code and copy/paste it into the challenge, it passes all four steps. Take a look:

// 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");
//camel-casing

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