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 trialBrandon Wash
Courses Plus Student 1,186 Pointshow exactly would you right out Print out to the screen using the printf method on console, "First name: " and the user'
how would this code be written
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What is your first name? ");
String lastName = console.readLine("What is your last name? ");
console.printf =
2 Answers
Stone Preston
42,016 Pointsyou need to use a %s format specifier with the printf method to print out the value of a variable inside the string:
console.printf("First name: %s", firstName);
the value of the variable firstName will be inserted into the string where the format specifier (%s) is.
Ken Alger
Treehouse TeacherBrandon;
Welcome to Treehouse!
You need to utilize the string formatter as discussed in the video. So, your console.printf
statement would need to look like:
console.printf("First name: %s", firstName);
Hope it helps and happy coding.
Ken
Brandon Wash
Courses Plus Student 1,186 PointsThanks Ken I certainly appreciate your feedback.
Brandon Wash
Courses Plus Student 1,186 PointsBrandon Wash
Courses Plus Student 1,186 PointsOkay thanks Stone. I definitely appreciate your feedback. I am just starting off in coding but I have a strong interest and desire to learn this language completely. Thanks