Example
System.out.printf("I %n am %na %n boy");
Exit
I am a boy
Explanation
It's better to use %n as an OS-independent newline instead of \n , and it's easier than using System.lineSeparator()
Why use %n , because in each OS a new line refers to a different character set,
Unix and modern Mac : LF (\n) Windows : CR LF (\r\n) Older Macintosh Systems : CR (\r)
LF is an abbreviation of Line Feed and CR is an abbreviation of Carriage Return . Control characters are written inside brackets. Thus, in each OS, a new line means something specific to the system. %n is agnostic, it is portable. It stands for \n on Unix systems or \r\n on Windows systems and so on. Thus, do not use \n , but use %n .
Levent Divilioglu Jun 28 '16 at 13:41 2016-06-28 13:41
source share