File tree Expand file tree Collapse file tree 6 files changed +96
-0
lines changed
src/main/java/com/javaprogramto/programs/escape/newline Expand file tree Collapse file tree 6 files changed +96
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 woops there is a new line.</p>" ;
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments