I had created a 2-dimensional selection in Java and I was looking for a method to publish it the end on the console so that I might confirm that the stuff i was making to be correct. I uncovered some code virtual that performed this task for me, but I had actually a question around what a certain bit the the password meant.

You are watching: What does mean in java

int n = 10;int<><> grid = new int;//some code taking care of populating Gridvoid PrintGrid() { for (int ns = 0; i What go "\n" do? i tried searching on Google, but since it"s such a little bit of code I couldn"t uncover much.


Its is a new line

Escape SequencesEscape sequence Description\t Insert a tab in the text at this point.\b Insert a backspace in the message at this point.\n Insert a newline in the text at this point.\r Insert a carriage return in the message at this point.\f Insert a formfeed in the message at this point.\" Insert a solitary quote personality in the text at this point.\" Insert a double quote character in the text at this point.\\ Insert a backslash personality in the text at this point.http://docs.oracle.com/javase/tutorial/java/data/characters.html


\n This means insert a newline in the text at this point.

Just example




(as every http://java.sun.com/...ex/Pattern.html)

The backslash character ("\") offer to introduce escaped constructs, as defined in the table above, and to quote personalities that otherwise would be taken as unescaped constructs. Thus the expression \\ matches a single backslash and also { matches a left brace.

Other instances of intake :

\\ The backslash character\t The tab character ("\u0009")\n The newline (line feed) personality ("\u000A")\r The carriage-return personality ("\u000D")\f The form-feed character ("\u000C")\a The alarm (bell) character ("\u0007")\e The escape character ("\u001B")\cx The regulate character matching to x


\nThat means a new line is printed.

As a side keep in mind there is no must write the extra line . Over there is an developed in inbuilt duty there.

println() //prints the contents in new lineLearn much more from docs


\n is an escape character because that strings that is changed with the new line object. Writing \n in a string the prints the end will publish out a new line instead of the \n

Java to escape Characters

In the specific case that the code instance from the original question, the

System.out.print("\n");is there to move to a new line between incrementing i.

So the very first print declare prints every one of the elements of Grid<0>. When the innermost for loop has completed, the "\n" gets printed and then all of the elements of Grid<1> are printed on the next line, and also this is repetitive until you have actually a 10x10 network of the aspects of the 2-dimensional array, Grid.

See more: Watch Dr Blake Mysteries Season 5 Online Free, The Doctor Blake Mysteries Season 5

\n is include a brand-new line.

Please note java has an approach System.out.println("Write message here");

Notice the difference:


System.out.println("Text 1");System.out.println("Text 2");Output:

Text 1Text 2Code:

System.out.print("Text 1");System.out.print("Text 2");Output:

Text 1Text 2

Not the prize you're looking for? Browse various other questions tagged java or asking your very own question.

site style / logo design © 2021 stack Exchange Inc; user contributions licensed under cc by-sa. Rev2021.9.28.40331

her privacy

By clicking “Accept every cookies”, girlfriend agree stack Exchange can store cookies on your an equipment and disclose details in accordance with our Cookie Policy.