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 trialNaphtali Matione
5,224 Pointssystem.out.println and system.out.printf
how do i know when to use either system.out.println or system.out.printf
2 Answers
Craig Dennis
Treehouse TeacherIf you want to print formatted text, IE: replace a value in a string using %s, you should use printf
.
You can actually concatenate strings using + and still use println, but IMO that is harder to read and a waste of effort when there is a tool developed specifically for that. println
adds a new line, there is also System.out.print
which does not.
That help?
Michael Newman
39,508 PointsI was confused about this as well, but I know it has to do with formatting the string you are printing. This is the best link I've found on the subject right now. http://docs.oracle.com/javase/tutorial/java/data/numberformat.html
Naphtali Matione
5,224 Pointsthanx micheal, il check it out
Naphtali Matione
5,224 PointsNaphtali Matione
5,224 Pointsthanx craig, u made crystal clear