search
HomeJavajavaTutorialWhat are the functions of \t,\n,\r,\b,\f in java

\t,\n,\r,\b,\f The role of

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:

What are the functions of \t,\n,\r,\b,\f in java

Conclusion

  • \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

\n\r\t\f

Generally summarize the functions of \n \r \t \f

##\nLine break \rEnter\tTab (equivalent to tab)\fPage change
Character Function
Explain the characteristics of each individually.

\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:

What are the functions of \t,\n,\r,\b,\f in java

\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:

What are the functions of \t,\n,\r,\b,\f in java

Here, it looks like After the previously output hello world was cleared, the same output as 1234 was returned. It's different from its original meaning. Shouldn't it be outputting "1234 world"?

However, the output result in the console is the result we expected:

What are the functions of \t,\n,\r,\b,\f in java

As for the reason, it should be related to the compiler.

\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:

What are the functions of \t,\n,\r,\b,\f in java

\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:

What are the functions of \t,\n,\r,\b,\f in java

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!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment