new line character in java
Hello
i was trying to figure out how to do the new line character in java according to this article
http://www.developer.com/design/arti...0925_3611496_2
Code:
public class Primitives {
public static void main(String[] args) {
char c2 = 'n'; // ASCII escape sequence for newline
System.out.println("c2 = " + (char)c2);
}
}
i tried the code, but i am getting the following output.
c2= n
i tried to change char c2 = '/n'
and i get the error unclosed character literal
does this article follow an old java standard which is not copatile with java 1.4?
p.s.
the artcle says
short num = 227; // is The code for PI
how ever i get some other character on the screen
Re: new line character in java
It's '\n', not '/n' and definitely not 'n'.
Hmm, I looked over the article, and I can only say, STAY AWAY! The slashes all have disappeared or are the wrong way round (the author starts comments with a single backslash instead of a double forward slash), he casts char to short (don't do that - if you have to cast char to an integral type, cast it to int, short is too small), ...
Re: new line character in java
I use
Code:
System.getProperties("line.separator")
I think it makes it platform independent.
Re: new line character in java
To get the platform line separator in text files, yes. But maybe he simply wants a newline, e.g. for a network protocol.
Re: new line character in java
thanks for the replies,
cornedbee, got your point, the articles came recommended by a couple of university website, that is why i have gone through them.
what do you mean by a network protocol?
Re: new line character in java
Well, HTTP for example requires you to use a \r\n pair to terminate every header line, regardless of the operating system.
Re: new line character in java
thanks for the reply dude, makes sense now.