print new line java code example

Example 1: java string next line

// its \r\n
String a = "Hello, "
String b = "there!"
System.out.println(a+b);//returns Hello, there
System.out.println(a+"\r\n"+b);//returns Hello, 
//there! //it will be on the next line!

Example 2: java how to go into newline while using print

// newline while using System.out.print();
System.out.print("First Line\nSecond Line");
//output:
//First Line
//Second Line

Example 3: java how to print without going into newline

System.out.print("Hello World!");
System.out.print("Bonjour Le Monde!");
// output: "Hello World!Bonjour Le Monde!" (all in one line)
// the lines that are greyed out are comments and act as notes

Example 4: java how to print a newline

System.out.println("<Your line here.>");