new line java code example
Example 1: how to skip a line in java
System.out.println();
Example 2: java string next line
String a = "Hello, "
String b = "there!"
System.out.println(a+b);
System.out.println(a+"\r\n"+b);
Example 3: java how to go into newline while using print
System.out.print("First Line\nSecond Line");
Example 4: java read next line
Scanner scanner = new Scanner(new File("filename"));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
}
Example 5: java new line
String line1 = "Humpty Dumpty sat on a wall.";
String line2 = "Humpty Dumpty had a great fall.";
String rhyme = line1 + "\n" + line2;
Example 6: how to print \n in a string in java
System.out.println("\\n hello world");