How to create a new line in Java output?
In Java, there are several ways to achieve line breaks when printing output.
- Can you please reword this sentence for me?
- Please provide a single option for paraphrasing the following text natively in English.
System.out.println("第一行\n第二行");
The output result:
第一行
第二行
- Prints to the console.
- display the output
System.out.println("第一行");
System.out.println("第二行");
Output:
第一行
第二行
- Print to the console.
- Output the information
System.out.print("第一行");
System.out.print("\n");
System.out.print("第二行");
Output result:
第一行
第二行
It should be noted that the above methods are all for console output. If you are outputting in a file, you can use System.getProperty(“line.separator”) to obtain the system’s default line separator.