Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

I have some code with me, and I don't able to understand what \n can do? Below is my code:

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");

    }

}

Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

Basically, \n helps you to create a new line. Similarly, we have different escape sequences:

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.

I hope this will help.

Want to become a Java expert? join Java Certification now!!

Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Programming:

Related questions

0 votes
1 answer
asked Jan 24, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Jan 21, 2020 in Java by angadmishra (6.5k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 25, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer

Browse Categories

...