Adding new line in printf() or format()

studentaccount4 :

today I was reading in the java Tutorials docs from Oracle about Formatting Numeric Print Output and I encountered println() vs printf() vs format() after I understood the differences I read the following sentence which makes no sense for me.

A new line character appropriate to the platform running the application. You should always use %n, rather than \n.

so the main question of this is why "should" I always use %n instead of \n what difference does this make?

Vishvak Seenichamy :

The %n is like a placeholder for whatever the newline character may be for a particular system. %n could very well be \n for a specific system or \r\n for another such as the case with windows. Using %n is the safer alternative to typing \n because as @user85421 commented, some windows applications don't recognize \n.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=396313&siteId=1