8 Replies - 135241 Views - Last Post: 24 March 2009 - 07:20 AM Rate Topic: -----

#1 nicole.zhedeng  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-March 09

what does"\n" mean

Posted 23 March 2009 - 08:50 PM

here is one simple questions i dont really understand


what does"\n" mean if it's in a statement, ex.

System.out.println ("Too short!\n") 

does it make a difference if \n is not in the statement?

thx!!!

This post has been edited by nicole.zhedeng: 23 March 2009 - 08:51 PM

Is This A Good Question/Topic? 0
  • +

Replies To: what does"\n" mean

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5226
  • View blog
  • Posts: 26,997
  • Joined: 10-May 07

Re: what does"\n" mean

Posted 23 March 2009 - 08:56 PM

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

The backslash character ('\') serves to introduce escaped constructs, as defined in the table above, as well as to quote characters that otherwise would be interpreted as unescaped constructs. Thus the expression \\ matches a single backslash and \{ matches a left brace.

Other examples of usage :

\\ The backslash character
\t The tab character ('\u0009')
\n The newline (line feed) character ('\u000A')
\r The carriage-return character ('\u000D')
\f The form-feed character ('\u000C')
\a The alert (bell) character ('\u0007')
\e The escape character ('\u001B')
\cx The control character corresponding to x

** Renamed title to be more descriptive of topic **
Was This Post Helpful? 0
  • +
  • -

#3 gana88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-March 09

Re: what does"\n" mean

Posted 23 March 2009 - 09:01 PM

\n means enter to wite in
new line
Was This Post Helpful? 0
  • +
  • -

#4 priya_lorha  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 78
  • Joined: 02-August 08

Re: what does"\n" mean

Posted 24 March 2009 - 03:48 AM

\n means new line.
A new line is printed after the first statement is printed

This post has been edited by priya_lorha: 24 March 2009 - 03:49 AM

Was This Post Helpful? 0
  • +
  • -

#5 Krissilla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 24-January 09

Re: what does"\n" mean

Posted 24 March 2009 - 04:42 AM

..a new liNe..
Was This Post Helpful? 0
  • +
  • -

#6 porky101  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 97
  • Joined: 23-September 08

Re: what does"\n" mean

Posted 24 March 2009 - 05:29 AM

a new line
Was This Post Helpful? 0
  • +
  • -

#7 Max2009  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 27-January 09

Re: what does"\n" mean

Posted 24 March 2009 - 05:34 AM

As a general rule of thumb the '\' means "do something special".
In Java, that means call the appropriate call (tab, new line etc') and in a command window (like Windows cmd or Linux console) it means ignore the next character.
If you need to type a filepath, and there are spaces in the folder names, that could be a problem, because command windows are space-sensitive. So, you use the '\' character before a space.
Example:
/root/My\ Documents
had you left out the '\' it would have said that it can't find the folder/filename "My". Using '\' effectively killed the space, and told it to read it as one filename.
Was This Post Helpful? 0
  • +
  • -

#8 get2tk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-March 09

Re: what does"\n" mean

Posted 24 March 2009 - 07:11 AM

means move to the next line
Was This Post Helpful? 0
  • +
  • -

#9 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: what does"\n" mean

Posted 24 March 2009 - 07:20 AM

Quote

System.out.println ("Too short!\n")

does it make a difference if \n is not in the statement?


In this particular instance the println method automatically adds a new line so in this you will be splitting an additional line in.

If you only want 1 line you can remove the \n like:
System.out.println ("Too short!")

This will not put in an extra line and is equavlent to:

System.out.print ("Too short!\n")

this is print and will not put an extra line in automatically when done.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1