I had produced a 2-dimensional range in Java and I was searching for a way to print it the end on the console so that I might confirm the the stuff i was making was correct. I uncovered some code virtual that perform this job for me, yet I had a question about what a details bit the the code meant.

You are watching: What does /n mean in java

int n = 10;int<><> network = new int;//some code dealing with populating Gridvoid PrintGrid() { because that (int ns = 0; ns What walk "\n" do? i tried looking on Google, but due to the fact that it"s such a tiny bit of password I couldn"t find much.


Its is a brand-new line

Escape SequencesEscape sequence Description\t Insert a tab in the message 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 message at this point.\f Insert a formfeed in the message at this point.\" Insert a single quote personality in the text at this point.\" Insert a dual quote character in the text at this point.\\ Insert a backslash character in the message at this point.http://docs.oracle.com/javase/tutorial/java/data/characters.html


\n This method insert a newline in the message at this point.

Just example




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

The backslash character ("\") serves to present escaped constructs, as identified in the table above, and also to quote characters that otherwise would certainly be taken as unescaped constructs. For this reason the expression \\ matches a solitary backslash and { matches a left brace.

Other examples of intake :

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


\nThat way a brand-new line is printed.

As a side note there is no should write the extra heat . Over there is an built in inbuilt function there.

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


\n is an escape character because that strings that is replaced with the new line object. Writing \n in a string that prints out will print out a brand-new line rather of the \n

Java escape Characters

In the details case that the code instance from the initial question, the

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

So the first print explain prints all of the elements of Grid<0>. As soon as the innermost for loop has actually completed, the "\n" it s okay printed and then every one of the aspects of Grid<1> are printed on the following line, and this is recurring until you have a 10x10 network of the aspects of the 2-dimensional array, Grid.

See more: Solved: Can The Entropy Of An Ideal Gas Change During An Isothermal Process?

\n is add a brand-new line.

Please note java has method 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 feather for? Browse other questions tagged java or questioning your very own question.

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

your privacy

By click “Accept all cookies”, girlfriend agree stack Exchange deserve to store cookies on your device and disclose info in accordance through our Cookie Policy.