Java - "\n"是什么意思?

标签 java

<分区>

我在 Java 中创建了一个二维数组,我正在寻找一种在控制台上打印它的方法,以便我可以确认我所做的东西是正确的。我在网上找到了一些为我执行此任务的代码,但我对代码的特定部分的含义有疑问。

int n = 10;
int[][] Grid = new int[n][n];

//some code dealing with populating Grid

void PrintGrid() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            System.out.print(Grid[i][j] + " ");
        }
        System.out.print("\n");
    }
}

“\n”是做什么的?我尝试在 Google 上搜索,但由于代码太少,我找不到太多内容。

最佳答案

这是一条新线

Escape Sequences
Escape Sequence Description
\t  Insert a tab in the text at this point.
\b  Insert a backspace in the text at this point.
\n  Insert a newline in the text at this point.
\r  Insert a carriage return in the text at this point.
\f  Insert a formfeed in the text at this point.
\'  Insert a single quote character in the text at this point.
\"  Insert a double quote character in the text at this point.
\\  Insert a backslash character in the text at this point.

http://docs.oracle.com/javase/tutorial/java/data/characters.html

来自 Java 语言规范。

EscapeSequence:
\ b (backspace BS, Unicode \u0008)
\ t (horizontal tab HT, Unicode \u0009)
\ n (linefeed LF, Unicode \u000a)
\ f (form feed FF, Unicode \u000c)
\ r (carriage return CR, Unicode \u000d)
\ " (double quote ", Unicode \u0022)
\ ' (single quote ', Unicode \u0027)
\ \ (backslash \, Unicode \u005c)

https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.6

关于Java - "\n"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19008970/

相关文章:

java - 带有嵌入式tomcat的spring-boot不会将请求分派(dispatch)给 Controller

java - 从 Android 访问工作中的 HTTPService 时遇到问题

java - jsf 成功时打开对话框

java - 如何获取某个月份的所有日期

java - 如何在 MaxOSX 中从 JDBC 调用 Oracle TimesTen

java - 如何用编译时泛型验证替换运行时instanceof检查

java - java程序出错时如何保持运行

java - 使用 keytool 更改密码时从 Java Keystore 中提取 PKCS12 文件

java - 批量执行多个sql语句的问题?

java - 错误的数据被分配给错误的变量