Carriage return in Java – how does it work

Today we are going to study a special character carriage return in Java. It is denoted by \r. Special characters are the character sequence that is used to perform a specific task.

Carriage return in Java – how does it work

It remains on the same line. All the text, written after it is put forward at the starting of the same line. It replaces the same number of old characters with new characters. Just like in Newline character (\n)  the cursor is moved to a new line.

System.out.println("hello world \r rafter \n nafter \f fafter");

output:

hello world 
 r-after 
 n-after  f-after

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top