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
Yongshuo Wang
5,500 PointsWhat is different between console.printf and System.out.println ?
When I learn Java from school, we use System.out.println, may I know what is the different from console.printf ?
1 Answer
Robert Richey
Courses Plus Student 16,352 PointsHi Yongshuo Wang,
println() will print a string with a newline at the end - and will not accept a formatted string.
printf() will print a formatted string - but will not add a newline to the end.
Both functions can be called from System.out.
String message = "Hello World!";
// the output from these two lines are equivalent
System.out.println(message);
System.out.printf("%s\n", message);
Yongshuo Wang
5,500 PointsYongshuo Wang
5,500 PointsThanks for your answer.