How to create a new line in Java output?

In Java, you can use “\n” to represent a line break, or you can use the System.out.println() method to achieve the same effect. Here are some example codes:

Use \n to create a line break.

System.out.print("第一行\n");
System.out.print("第二行\n");

Print a newline using the System.out.println() method.

System.out.println("第一行");
System.out.println("第二行");

Both methods can achieve line breaks, the choice of which method to use depends on your needs and coding style.

bannerAds