Home >Java >javaTutorial >What are the functions of \t,\n,\r,\b,\f in java
You will know by looking at the direct output
System.out.println("11111\ t2225222");System.out.println("55555\n665666");System.out.println("88877\r5454421\n");System.out.println("777458\b6594954");System.out.println ("777788\f6594954");
Output result:
\t
Equivalent to the tab key
\b
Backspace
\ f
The console output is equivalent to the following figure
\n
Newline
\r
Enter
Enter\r The original meaning is to return the cursor to the beginning of the line. The English return of r, the control character can be written as CR, that is, Carriage Return
line break \n The original meaning is that the cursor goes to the next line (not necessarily to the beginning of the next line). n's English newline, the control character can be written as LF, that is, the difference between Line Feed
Character | Function |
---|---|
Line break | |
Enter | |
Tab (equivalent to tab) | |
Page change |
\n Newline character, positioning the cursor to the next line.
public class Test { public static void main(String[] args) { System.out.print("aaaaaaaaaaaaa\nbbbb"); } }Result:
\r The carriage return character returns the cursor to the beginning of the current line. If there was content on the line before, it will be overwritten;
public class Test { public static void main(String[] args) { System.out.println("hello world\r12345"); } }The compiler output is:
\t is the tab character. Equivalent to tab indentation.
It will make the content you output be a multiple of 4. If the string "a\t" is output, then 3 spaces will be output after a. If the string aaaa\ is output, t, then four spaces will be output after 4 a’s are output. So what if it outputs aaaaa\t? , it will output 3 spaces after it, so that the number of characters output is exactly a multiple of 4. The following is the test code;public class Test { public static void main(String[] args) { System.out.println("a\t*"); System.out.println("123412341234"); System.out.println("aaa\t*"); System.out.println("123412341234"); System.out.println("aaaa\t*"); System.out.println("123412341234"); System.out.println("aaaaa\t*"); System.out.println("123412341234"); } }The result:
\f is the form feed character, output on the console Pointless.
Demonstrate here:public class Test { public static void main(String[] args) { System.out.println("aaaa\fbbbb"); } }Result:
The above is the detailed content of What are the functions of \t,\n,\r,\b,\f in java. For more information, please follow other related articles on the PHP Chinese website!