我用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“是做什么的?我试着在谷歌上搜索,但由于代码太少,我找不到太多。
发布于 2013-09-25 23:26:02
Its是一条新的线路
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
发布于 2013-09-25 23:26:43
\n 这意味着在文本中插入一个换行符。
举个例子
System.out.println("hello\nworld");输出:
hello
world发布于 2013-09-25 23:25:26
\n这意味着打印了一个新行。
顺便说一句,不需要写额外的行。这里有一个内置的函数。
println() //prints the content in new lineLearn more from docs
https://stackoverflow.com/questions/19008970
复制相似问题