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!