问题
What is the difference between %n and \n in Java?
For example,
System.out.printf("Hello, world! %n");
and
System.out.printf("Hello, world! \n");
Both return the same output for me.
回答1:
Well, as far as i know the difference is that %n will always output the correct line break depending on the platform while \n won't.
来源:https://stackoverflow.com/questions/50366242/using-n-or-n-in-java-to-format-string