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

Chukwuemeka Anene
Chukwuemeka Anene
108 Points

How am i supposed to pass the firstName parameter to the printfunction?

Really confusing right now

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = "Chukwuemeka";
console.readLine("firstName");
String lastName = "Anene";
console.readLine("lastName");
console.readLine("What is your name?"  );
console.printf("%s\n First name:", firstName);
Lukas Baumgartner
Lukas Baumgartner
14,817 Points

1) You use the readLine method to read what the user types into the console. You do not have to / must not add your first name /last name directly in the code.

Try to safe the user input for the first name directly into the firstName variable. Same goes for the lastName.

2) Your output would look like this:

Chukwuemeka
First name:

You have to place the %s placeholder somewhere else :)

Try to rewatch the video again and type along with Craig! Let me know if you have any more difficulties :)

1 Answer

Chukwuemeka Anene
Chukwuemeka Anene
108 Points

Hi Lukas,

Thanks for the tip. i was able to pass this exercise by watching the video again. And the code i used is different from my initial post.

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

Lukas Baumgartner
Lukas Baumgartner
14,817 Points

Nice! :)

It will be even more efficient if you do it like this:

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