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 trialSteven Couture
2,106 PointsWhy use console.printf instead of System.out.println? or will that be discussed later?
?????
4 Answers
Zac Mazza
5,867 PointsSystem.out.println is able to print using variable substitution, but by using printf you can simplify mixing variables with text. For example, instead of System.out.println("Hello, my name is " + yourName + " and I am " + age + " years old.), I can instead use printf and say console.printf("Hello, my name is %s and I am %i years old.", yourName, age);. When using several variables in your output, it can be beneficial to use printf. You can also use this to format the output of the variables, such as converting numbers to dollar amounts.
Hope this helps.
Zac
Lucas van der Laan
4,026 PointsPrintf makes it shorter AND easier to use variables in your output.
It also is useful for if you want to print x, where x = 0.50 instead of 0.5000001;
double x = 0.5000001;
Zac Mazza
5,867 PointsGood point, and I'm not sure the answer to that. Ultimately it comes down to making the I/O of System easier to access. One of the videos mentions that Console is a wrapper class.
printf is available for both System.out and Console. I suppose it comes down to preference. :-)
Simon Coates
28,694 PointsSimon Coates
28,694 Pointsis that what he was asking? I assumed it was ultimately about why you'd go with the Printstream object over the Console object.