The line breaks that can be used in java are: "\n" means new line, "\r" means carriage return, \r \n".
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:
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:
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:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.