Joke Collection Website - Blessing messages - What is the meaning and difference between carriage return and line feed in java?

What is the meaning and difference between carriage return and line feed in java?

\r Enter is to move the cursor to the front of a line.

\n Yes, move to the next line.

I'll analyze it for you sentence by sentence.

1 represents the cursor position.

system . out . print(" a ");

Output:

a 1

system . out . print(" \ n ");

Output:

a

1

system . out . print(" b ");

a

b 1

system . out . print(" \ r ");

a

1b

Note that the carriage return here moves the cursor in front of B, so B will be replaced when C is output next time.

system . out . print(" c ");

a

c 1

The following is the same.

Analyze it yourself.