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

challenge task 3 of IO.java " console print f problems

I cannot figure out how to print out the firstname and the users first name. is there a error in the question? iv'e been on this for 3 hours and still can't get it someone please show me

thanks Justin

Logan R
Logan R
22,989 Points

Can you please post the code for your latest attempt?

Hi logan

i found the code that i needed, console.printf("Firstname: %s", firstName);

thanks logan

Logan R
Logan R
22,989 Points

Glad you did :) Do you understand what that code does?

Im still a little confused. Im sure its so you dont have to change every name in the code.

1 Answer

Logan R
Logan R
22,989 Points

Printf means print formatted. It formats the string. So if you have a list and you want it to look pretty, you can provide auto white space so everything is aligned right. You can also format floats/doubles so they only show the first two decimal places, for example.

Printf takes "2" arguments (It actually takes in unlimited, but there are 2 main components). The string to be formatted, and everything to be updated. So say we had a name and a float:

String name = "Gameboy";
float weight = 12.405848459083405830485034856;

System.out.printf("The %s weighs %.2f pounds", name, weight);

The following would say "The Gameboy weighs 12.40 pounds."

I hope this makes printf a tad bit more clear.