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

Brandon Wash
PLUS
Brandon Wash
Courses Plus Student 1,186 Points

how 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

IO.java
// 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
Stone Preston
42,016 Points

you 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.

Brandon Wash
Brandon Wash
Courses Plus Student 1,186 Points

Okay 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

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Brandon;

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
Brandon Wash
Courses Plus Student 1,186 Points

Thanks Ken I certainly appreciate your feedback.