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 trialViktor Kuryshev
2,021 Pointsprintln and printf have different behaviour?
Seems that System.out.println - does not permit %s things - gives error at compiling and printf - works ok.
2 Answers
Alexander Davison
65,469 PointsThat's right! Printf is short for Print Format, and Println is short for Print Line. %s stuff is called formatting, so that means that printf supports formatting and println doesn't. :)
Hope this helps, Alex
Piyush Patel
17,253 PointsYeah, printf() takes another arguments to print whatever you want to print. It actually formats the message and then prints. For example
System.out.printf("The error was: %s\n", iae.getMessage());
Here, we are telling the compiler to add the message from iae.getMessage() and replace '%s'.
Println only prints the line. Whatever you supply as argument will be printed.