首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java - "\n“是什么意思?

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

Stack Overflow用户
提问于 2013-09-25 23:24:39
回答 7查看 478.7K关注 0票数 14

我用Java创建了一个二维数组,我正在寻找一种在控制台上打印出来的方法,这样我就可以确认我制作的东西是正确的。我在网上找到了一些为我执行这项任务的代码,但我有一个问题,那就是代码中的某一部分是什么意思。

代码语言:javascript
复制
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“是做什么的?我试着在谷歌上搜索,但由于代码太少,我找不到太多。

EN

回答 7

Stack Overflow用户

发布于 2013-09-25 23:26:02

Its是一条新的线路

代码语言:javascript
复制
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

票数 42
EN

Stack Overflow用户

发布于 2013-09-25 23:26:43

代码语言:javascript
复制
\n 

这意味着在文本中插入一个换行符。

举个例子

代码语言:javascript
复制
System.out.println("hello\nworld");

输出:

代码语言:javascript
复制
hello
world
票数 8
EN

Stack Overflow用户

发布于 2013-09-25 23:25:26

代码语言:javascript
复制
\n

这意味着打印了一个新行。

顺便说一句,不需要写额外的行。这里有一个内置的函数。

代码语言:javascript
复制
 println()  //prints the content in new line

Learn more from docs

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19008970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档