Using %n or \n in Java to format String [duplicate]

北慕城南 提交于 2019-12-11 17:43:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!