Java 中换行可使用以下符号表示:\n代表回车换行符(Windows),\r\n代表回车换行符序列(Windows)。推荐使用\n表示换行,以实现跨平台兼容。

Java 中换行的表示
在 Java 中,换行可以使用以下两种符号表示:
1. \n
\n 代表回车换行符,它在 Windows 操作系统中表示换行。它将光标移动到下一行的开头。
立即学习“Java免费学习笔记(深入)”;
2. \r\n
\r\n 代表回车换行符序列,它在 Windows 操作系统中表示换行。它将光标移动到下一行的开头,并将其置于该行的开头。
在 Unix 和 Linux 操作系统中,换行符仅使用 \n 表示。因此,在多平台代码中,建议使用 \n 来表示换行。
示例
下面的代码示例演示了如何在 Java 中使用 \n 和 \r\n 换行:
<code class="java">System.out.println("This is the first line.\nThis is the second line.");</code>上面的代码将在控制台中打印以下内容:
<code>This is the first line. This is the second line.</code>
<code class="java">System.out.println("This is the first line.\r\nThis is the second line.");</code>上面的代码将在控制台中打印以下内容:
<code>This is the first line. This is the second line.</code>











