Home  >  Article  >  What are the newline characters in java?

What are the newline characters in java?

青灯夜游
青灯夜游Original
2019-02-23 11:16:049058browse

The line breaks that can be used in java are: "\n" means new line, "\r" means carriage return, \r \n".

What are the newline characters in java?

In java, you need to include the newline character "\n", "\r" or "\r \n" at the end of the string (text) to perform a newline.

The newline character "\n"

"\n" is also called line break and is generally used in operating systems based on Unix/Linux/New Mac.

Example:

public class A {
    public static void main(String []args) {
   System.out.println("字母A"+"字母B");
       System.out.println("字母A"+"\n"+"字母B");
    }
}

Output:

What are the newline characters in java?

Newline character "\r"

"\r ” also known as carriage return, generally used in operating systems based on older Macs.

Example:

public class A {
    public static void main(String []args) {
   String line1 = "php中文网";
       String line2 = "学习PHP!";
       String rhyme = line1 + "\r" + line2;
       System.out.println(rhyme);
    }
}

Output:

What are the newline characters in java?

Line break "\r \n"

"\r \n" is a combination of "\r" and "\n", generally in Windows-based operations Used in the system.

Example:

public class A {
    public static void main(String []args) {
   String line1 = "php中文网";
       String line2 = "学习PHP!";
       String rhyme = line1 + "\r\n" + line2;
       System.out.println(rhyme);
    }
}

Output:

What are the newline characters in java?

The above is the entire content of this article, I hope it can be helpful to everyone Learning is helpful. For more exciting content, you can pay attention to the relevant tutorial columns of the php Chinese website!!!

The above is the detailed content of What are the newline characters in java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn