8000 Java Escape Sequences · TGAMendis/CoreJava@86c622a · GitHub
[go: up one dir, main page]

Skip to content

Commit 86c622a

Browse files
author
JavaProgramTo.com
committed
Java Escape Sequences
1 parent 4b746b8 commit 86c622a

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.javaprogramto.programs.escape.sequences;
2+
3+
public class EscapeSequencesExample1 {
4+
5+
public static void main(String[] args) {
6+
7+
String newLineEscapeSequence1 = "\n";
8+
System.out.println("\\n length is "+newLineEscapeSequence1.leng 8000 th());
9+
10+
11+
String newLineEscapeSequence2 = "\n\n";
12+
System.out.println("\\n\\n length is "+newLineEscapeSequence2.length());
13+
14+
15+
String tabEscapeSequence1 = "\t";
16+
System.out.println("\\t length is "+tabEscapeSequence1.length());
17+
18+
19+
String backslashEscapeSequence1 = "\\";
20+
System.out.println("\\\\ length is "+backslashEscapeSequence1.length());
21+
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.javaprogramto.programs.escape.sequences;
2+
3+
public class EscapeSequencesExample2 {
4+
5+
public static void main(String[] args) {
6+
7+
// octal escape sequence examples
8+
String octalEscape1 = "\52";
9+
10+
System.out.println("\\52 octal represntation is " + octalEscape1);
11+
12+
String octalEscape2 = "\53";
13+
14+
System.out.println("\\53 octal represntation is " + octalEscape2);
15+
16+
// unicode escape sequence examples
17+
18+
String unicodeEscape1 = "\u5222";
19+
20+
System.out.println("\\u5222 unicode represntation is " + unicodeEscape1);
21+
22+
String unicodeEscape2 = "\u5333";
23+
24+
System.out.println("\\u5333 unicode represntation is " + unicodeEscape2);
25+
}
26+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.javaprogramto.programs.escape.sequences;
2+
3+
public class EscapeSequencesExample3 {
4+
5+
public static void main(String[] args) {
6+
7+
// newline \n escape sequence
8+
String newlineEscape = "hello\nworld";
9+
System.out.println("\nnewline : ");
10+
System.out.println(newlineEscape);
11+
12+
// tab \t escape sequence
13+
String tabEscape = "hello\tworld";
14+
System.out.println("\ntab : ");
15+
System.out.println(tabEscape);
16+
17+
// backspace \b escape sequence
18+
String backspaceEscape = "hello\bworld";
19+
System.out.println("\nbackspace : ");
20+
System.out.println(backspaceEscape);
21+
22+
// carriage \r escape sequence
23+
String carriageEscape = "hello\rworld";
24+
System.out.println("\ncarriage : ");
25+
System.out.println(carriageEscape);
26+
27+
// form feed \f escape sequence
28+
String formfeedEscape = "hello\fworld";
29+
System.out.println("\nform feed : ");
30+
System.out.println(formfeedEscape);
31+
32+
// single quote \' escape sequence
33+
String singlequoteEscape = "hello\'world";
34+
System.out.println("\nsingle equote : ");
35+
System.out.println(singlequoteEscape);
36+
37+
// double quote \" escape sequence
38+
String doublequoteEscape = "hello\"world";
39+
System.out.println("\ndouble quote : ");
40+
System.out.println(doublequoteEscape);
41+
42+
// backslash \\ escape sequence
43+
String backslashEscape = "hello\\world";
44+
System.out.println("\nbackslash : ");
45+
System.out.println(backslashEscape);
46+
}
47+
}

0 commit comments

Comments
 (0)
0