我正在阅读《Effective Java》,它到处都使用 %n
作为换行符。我已经相当成功地在 Java 程序中使用 \n
来换行。
哪一个是“正确的”? \n
有什么问题吗?为什么 Java 改变了这个 C 约定?
最佳答案
来自快速谷歌:
There is also one specifier that doesn't correspond to an argument. It is "%n" which outputs a line break. A "\n" can also be used in some cases, but since "%n" always outputs the correct platform-specific line separator, it is portable across platforms whereas"\n" is not.
请引用 https://docs.oracle.com/javase/tutorial/java/data/numberformat.html
关于java - Java printf 中的 "%n"是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23042419/