我用 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”有什么作用?我尝试在谷歌上搜索,但由于代码很小,所以我找不到太多。
这是一条新线
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 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 https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.6
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)