[JAVA] The right way for Line Breaks

Questions/Tutorials for any programming language not covered in other sections.
2 posts Page 1 of 1
Contributors
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

[JAVA] The right way for Line Breaks
Shim
Hey guys,

Introduction
In this JAVA tutorial we will see how to make line breaks in the right way.

Old methods
Actually not OLD methods they are still used but when it comes to Cross Platform they doesn't work.

beginners use for line breaks :
Code: Select all
System.out.println("\n");


actually it works but one thing every java programmers should know; if you use "\n" it can only work on Windows so it's a big problems and by the way on Mac for a line break in java you must use "\r" and on Linux it's"\r\n".

Now if you want to make a line break that works on all platforms(Windows, Mac, Linux etc), there's a way.

Make a public string(this line should be placed before the main event like C#)
Code: Select all
public static String newline = System.getProperty("line.separator");
Now whenever you want to make a line break all you have to do is print the string lol
Code: Select all
System.out.println(BR);
It will make a line break and it will work on all java supported platforms.

After a longtime wrote a tutorial on C'N'S( ..and testing my right hand lol) If you find this helpful don't forget give a +REP.

PS : don't mind my bad english lol
Find my programs on Softpedia
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

very useful tut.
2 posts Page 1 of 1
Return to “Misc”