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

Victor Warner
Victor Warner
1,882 Points

Print out to the screen using the printf method on console, "First name: " and the user's first name. Please show ex

Please show some examples on your questions otherwise it takes a long time to figure out what was wrong or even how a clue. thanks love treehouse GJ

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("Ben  ");
String lastName = console.readLine("Ass  ");
console.printf("Hello, my name is %s\n", "Ben  ");
console.printf("%s is learning how to write Java\n", "Ben  ");

2 Answers

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Victor

Not sure if your still struggling with this, the code you need to pass the challenge is below, below the code is the explanation

// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("Please enter your first name:     ");
String lastName = console.readLine("Please enter your last name:     ");
console.printf("First name: %s",firstName);
console.printf("Last name: %s",lastName);

Right line one and two tell the program to insert whatever the user types in after the message on each prompt into the variable named either firstName or lastName, the call to console.readLine() takes an optional parameter (a string) as a prompt message so the user knows what to type, so in this case I've simply put "please enter your x name".

The last 2 lines print out the 2 string as requested by the question in order to pass, it would be a hell of a lot better however like the code examples above to insert a line break or two after the initial call to printf() to make it more legible but it isn't required.

Hope this helps Daniel

Victor Warner
Victor Warner
1,882 Points

thank you i think i got it now i was stomped on this for like 1 hrs

Allan Clark
Allan Clark
10,810 Points

This passed the objective when I copied and pasted it, though to be exact you should replace "Ben " on the last two lines with firstName and lastName.

Hope this helps Hit me if you have any questions

Victor Warner
Victor Warner
1,882 Points

String firstName = console.readLine("Ben "); String lastName = console.readLine("Ass "); console.printf("Hello, my name is %s\n", firstName); console.printf("%s is learning how to write Java\n", firstName); console.printf("Hello, my name is %s\n", lastName); console.printf("%s is learning how to write Java\n", lastName);

why is it not working I have tried so many different variations!!!