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, "First name: ", followed by the first name? need help

i dont understand what they are asking me to do it seems like i would use console.readLine

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine ("Miegel");
String lastName = console.readLine ("Brown");
console.readLine = ("First name: Miegel");

3 Answers

Here, you're to ask the user for their input so instead of typing your name try this instead: String firstName = console.readLine("What is your first Name? ");

With this when it runs, the user can type in their first Name.

Hope this helps!

Also, with Challenge 3 and 4. this is where we use the console.printf to display the first and last names of the user. So it goes like this; console.printf("First Name: %s", firstName); And for the last name too; console.printf("Last Name: %s",lastName);

The %s represents the String we have declared in the bracket.

Hope it helps!

michaelcodes
michaelcodes
5,604 Points

Hi Eugene! You can format code when posting a comment by wrapping it with 3 ` and the name of the language.. see the "markdown cheatsheet" at the bottom of the page below for explanation

luke moloney
luke moloney
2,347 Points

Thank you Eugene, I got stuck here for some reason and this was super helpful.

michaelcodes
michaelcodes
5,604 Points

Hi there, to add to what Eugene said, after you have declared the variable (as user input)

String firstName = console.readLine ();

OR, if you want to display a message to the user such as "Please enter a name" you can do that too:

String firstName = console.readLine("Please enter a name");

Then to print out the variable specifically you would the formatted string:

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

Happy coding!

i got it with console.printf it was a = in between it i was looking over lol thinks by the way