В Java существует несколько способов создания новой строки. Вот некоторые из распространенных методов:
-
Использование символа новой строки:
System.out.println("This is the first line.\nThis is the second line."); -
Использование метода
System.lineSeparator():System.out.println("This is the first line." + System.lineSeparator() + "This is the second line."); -
Использование метода
System.getProperty():System.out.println("This is the first line." + System.getProperty("line.separator") + "This is the second line."); -
Использование метода
println()и пустой строки:System.out.println("This is the first line."); System.out.println("This is the second line."); -
Использование метода
printf()и спецификатора формата%n:System.out.printf("This is the first line.%nThis is the second line.");
Эти методы позволяют создавать новую строку в Java и обычно используются в различных сценариях.