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 trialJustin Rose
12,842 Pointschallenge 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
Justin Rose
12,842 PointsHi logan
i found the code that i needed, console.printf("Firstname: %s", firstName);
thanks logan
Logan R
22,989 PointsGlad you did :) Do you understand what that code does?
Justin Rose
12,842 PointsIm still a little confused. Im sure its so you dont have to change every name in the code.
1 Answer
Logan R
22,989 PointsPrintf 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.
Logan R
22,989 PointsLogan R
22,989 PointsCan you please post the code for your latest attempt?