Skip to content

Commit c241034

Browse files
author
JavaProgramTo.com
committed
java add new line
1 parent 86c622a commit c241034

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.javaprogramto.programs.escape.newline;
2+
3+
public class AddNewLineExample1 {
4+
5+
public static void main(String[] args) {
6+
7+
String line1 = "Hello engeers";
8+
String line2 = "hope you are staying safe";
9+
10+
String line3 = line1 + "\n" + line2;
11+
12+
System.out.println("Mac or unix or linux newline with \\n");
13+
System.out.println(line3);
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.javaprogramto.programs.escape.newline;
2+
3+
public class AddNewLineExample2 {
4+
5+
public static void main(String[] args) {
6+
7+
// windows os
8+
String line1 = "Hello engeers";
9+
String line2 = "hope you are staying safe";
10+
11+
String line3 = line1 + "\r\n" + line2;
12+
13+
System.out.println("windwos print newline with \\r\\n");
14+
System.out.println(line3);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.javaprogramto.programs.escape.newline;
2+
3+
public class AddNewLineExample3 {
4+
5+
public static void main(String[] args) {
6+
7+
// old mac os based
8+
String line1 = "Hello engeers";
9+
String line2 = "hope you are staying safe";
10+
11+
String line3 = line1 + "\r" + line2;
12+
13+
System.out.println("Old mac os print newline with \\r");
14+
System.out.println(line3);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.javaprogramto.programs.escape.newline;
2+
3+
public class AddNewLineExample4 {
4+
5+
public static void main(String[] args) {
6+
7+
// Using java api system class getProperty() method
8+
String line1 = "Hello engeers";
9+
String line2 = "hope you are staying safe";
10+
11+
String line3 = line1 + System.getProperty("line.separator") + line2;
12+
13+
System.out.println("print newline with System.getPropertyr() method");
14+
System.out.println(line3);
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.javaprogramto.programs.escape.newline;
2+
3+
public class AddNewLineExample5 {
4+
5+
public static void main(String[] args) {
6+
7+
// Using system dependent %n
8+
String line1 = "Hello engeers%nwelcome to the java blog";
9+
10+
System.out.println("print newline with %n line separator");
11+
System.out.printf(line1);
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.javaprogramto.programs.escape.newline;
2+
3+
public class AddNewLineExample6 {
4+
5+
public static void main(String[] args) {
6+
7+
// html break tag
8+
String tag1 = "<p>hello</p>";
9+
String tag2 = "<p>world</p>";
10+
11+
String tag3 = tag1 + "</br>" + tag2;
12+
13+
// using java \n
14+
String tag4 = tag1 + "\n" + tag3;
15+
16+
// using unicodes
17+
18+
String tag5 = "<p>This is paragraph text and &#13; woops there is a new line.</p>";
19+
}
20+
}

0 commit comments

Comments
 (0)