+ 2
Pls whats the meaning of this in java "/n"
"/n"
10 Antworten
+ 30
"\n" is new line. (not /n)
System.out.println("Peter\nThankGod");
Output :
Peter
ThankGod
+ 13
An escape sequence \n,
is used to move to the next line
+ 10
this known in CPP as "new line" .
+ 10
cout<<endl; or cout<<" \n"; same thing it moves to a new line .
+ 8
its same as <br> of html
and /n is used in js
+ 8
/n does nothing, it's just /n.
What you mean to say is \n. This puts the console to a new line.
Example:
System.out.println("example\ntest");
Output:
example
test
Where as I would have needed to write this to get the equivalent output:
System.out.println("example");
System.out.println("test");
\ is an escape character in a string, which allows you to interpret a different set of characters instead of having the \.
example:
\t -> equivalent to tabbing text
if you want to get a \ (character) then use \\.
You can see a further list of escape characters here:
https://docs.oracle.com/javase/tutorial/java/data/characters.html
There's also plenty of other explanations on what \n is encase your still confused here:
https://www.sololearn.com/Discuss/264168/why-writing-n-inside-the-cout-statement-it-prints-n
https://www.sololearn.com/Discuss/158151/use-of-n
+ 2
It creates a new line.
+ 1
It is string.
+ 1
I understand now; thanks