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

Peter Kurkowski
Peter Kurkowski
595 Points

I have no idea how to complete this challenge

I dont understand what it's asking i'm doing exactly what its saying.

IO.java
String firstName = ("Pete");
console.readLine("Pete");
String lastName= ("Kurkowski");
console.readLine("Kurkowski");
console.printf("First name:%s\n",firstName);

3 Answers

Paul Ryan
Paul Ryan
4,584 Points

It is asking you to store the value the user inputs in the string variable.

I will give you a helping hand.

String firstName = console.readLine();

In the code above I am storing whatever input the user gives in the String variable called firstName.

The readLine method reads input from the user.

Peter Kurkowski
Peter Kurkowski
595 Points

Thanks! Makes more sense now.

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Peter,

To set a variable to the result of a function, you'll need to declare the type of the variable, the name and assign it to the output of a method. For example, for first name you would do this.

String firstName = console.readLine();

Then print the first name like this.

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

I hope this helps.

String firstName = console.readLine("Enter first name: ");
String lastName = console.readLine("Enter last name: ");
console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);