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 Objects (Retired) Delivering the MVP Validation

system.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
STAFF
Craig Dennis
Treehouse Teacher

If 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?

thanx craig, u made crystal clear

I 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

thanx micheal, il check it out