0

Difference between \r and \n escape characters?

public class Program { public static void main(String[] args) { System.out.println("Hello\rWorld"); //Output: Hello // World System.out.println("Hello\nWorld"); //Output: Hello // World } } There's the same output. Could someone explain me what's the difference between \r and \n escape characters? Maybe with a short example.

13th Aug 2018, 10:44 AM
Adam
Adam - avatar
2 Antworten
+ 4
>>> print('Hello\rWorld') World >>> print('Hello\nWorld') Hello World https://stackoverflow.com/questions/7372918/whats-the-use-of-r-escape-sequence
13th Aug 2018, 11:29 AM
Mert Yazıcı
Mert Yazıcı - avatar
0
\r is a carriage return, it has the same function as a new-line, but was used on mac OS until mac OS X, \n is a new line character used for linux systems (and mac OS X), and "\r\n" is for windows systems java supports all of these because java can be used on any OS
13th Aug 2018, 12:06 PM
hinanawi
hinanawi - avatar