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 trialBinyamin Friedman
14,615 PointsWhy did he write the "%n" in: System.out.printf("The dispenser is %s %n", dispenser.
I just don't understand the explanation he gave in the video.
3 Answers
Matthew Edmondson
570 PointsFrom what I understand \n will usually work just fine as a line break, but may have some compatibility problems on some systems. %n isn't assigned an argument like %s or %f and has better compatibility as a line break across more platforms.
Diwesh Saxena
Courses Plus Student 756 PointsLike Matthew Edmondson pointed, it is just to ensure compatibility on some systems. You can very well try replacing the "%n" here with the usual "\n". It will still execute the same way.
John Anselmo
Courses Plus Student 2,281 Points%n is relatively new. \n and %n will always work, however %n is used cross platform because \n will not always work the same on every device/IDE
Binyamin Friedman
14,615 PointsBinyamin Friedman
14,615 PointsI didn't realize it was a line breaker. Thanks!