I had developed a 2-dimensional range in Java and I was looking for a way to publish it the end on the console so that I can confirm the the stuff ns was making was correct. I found some code digital that perform this job for me, however I had a question about what a certain bit that the password meant.

You are watching: What does mean in java

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


Its is a new line

Escape SequencesEscape succession 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 message at this point.\r Insert a carriage return in the text at this point.\f Insert a formfeed in the message at this point.\" Insert a solitary quote character in the text at this point.\" Insert a twin quote personality in the message 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 message at this point.

Just example




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

The backslash personality ("\") offer to introduce escaped constructs, as identified in the table above, and to quote characters that otherwise would certainly be understood as unescaped constructs. Therefore the expression \\ matches a solitary backslash and also { matches a left brace.

Other instances of usage :

\\ 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 character ("\u000C")\a The alert (bell) character ("\u0007")\e The escape character ("\u001B")\cx The regulate character equivalent to x


\nThat means a brand-new line is printed.

As a side keep in mind there is no have to write the extra line . There is an constructed 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 replaced with the new line object. Writing \n in a string the prints out will publish out a new line instead of the \n

Java to escape Characters

In the certain case the the code example from the initial question, the

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

So the first print statement prints all of the elements of Grid<0>. When the innermost for loop has actually completed, the "\n" it s okay printed and also then all of the aspects of Grid<1> are published on the following line, and this is repetitive until you have a 10x10 net of the facets of the 2-dimensional array, Grid.

See more: American Red Cross 335 Sw 27Th Ave Miami Fl 33135, 335 Sw 27Th Ave, Miami, Fl 33135

\n is add a brand-new line.

Please note java has technique System.out.println("Write text 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 ask your very own question.

site style / logo © 2021 ridge Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.9.17.40238

your privacy

By click “Accept every cookies”, girlfriend agree stack Exchange can store cookies on your maker and disclose information in accordance v our Cookie Policy.