我在 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