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 trialMartin Geil
432 PointsHey! :) What I did Wrong?
?
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("Martin");
String lastName = console.readLine("Geil");
String FirstName = console.printf ("%s");
2 Answers
Steve Hunter
57,712 PointsHi Martin,
You're almost there:
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What is your first name?: "); // user answers here
String lastName = console.readLine("What is your last name?: ");
console.printf("First name: %s", firstName); // value of firstName goes where the %s is
console.printf("Last name: %s", lastName);
So, you declare the String
objects first, and assign the values into them using user input, that's what the reaLine()
method does. The user answers the question, and that answer gets stored in the variables, firstName
and lastName
.
We then output those strings using a formatted printf
. For that, we put the %s
where we want the variable value to go. So the output string First name: %s
will be followed with the firstName
variable and the value of that variable will be inserted where the %s
is. Have a look at the code to see what I mean.
I hope that helps you out.
Steve.
Martin Geil
432 PointsThanks, good explonation
Steve Hunter
57,712 PointsNo problem - happy to help.
Steve.
Martin Geil
432 PointsMartin Geil
432 Pointsooou... thanks a lot :)
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI just added some more in-depth commentary to my initial answer. Let me know if you still have any questions.
Steve.