Difference between \ r and \ n JAVA

2

are known as escape sequences. I have been testing some, and I have seen that \ r and \ n generate new lines, although they have different definitions and as I have read, also different functions. Does anyone know the difference?

System.out.print("Diferencia entre usar \r");
System.out.print("O usar \n");

If it works, I leave this link, although I have not understood your explanation very well: link

    
asked by unanobot 11.06.2018 в 18:31
source

1 answer

7

They are not really the same, the definitions can give you an idea of how they work:

  

\n : (Line Feed) moves the cursor to the next line without returning to the beginning   of the line.

     

\r : Carriage return (Carriage return), move the cursor to the beginning of the line without advancing to the next line.

Both \r\n are commonly used. This to start a new line. Move the cursor to the beginning of the line ( \r ) and move the cursor to the next line ( \n ).

An analogy of which precisely the descriptions were obtained would be the one that is added in the Blog Penguin Pete's , where it shows an old typewriter ( Typewriter ).

Return car, move to the beginning of the line to write but we need to change the line to not write about it, then move the lever (line feed).

    
answered by 11.06.2018 / 18:35
source