Page 59 - CA_Blue( J )_Class9
P. 59
4.3.1 How to use Escape Sequence in Bluej?
Let us learn the use of Escape Sequence one by one.
Horizontal Tab (\t)
It is used to separate two values on the screen as output with a gap of tab spaces between them. It is used mainly
to print according to a given format.
Program 3 Write a program to demonstrate the use of \t.
1 class escapesequence_t
2 {
3 public static void main()
4 {
5 System.out.println("Good Morning:\tStudents");
6 }
7 }
You will get the following output:
New Line (\n)
It is used to print the characters which are encountered after \n in the next line. It is also known as newline
character. You can think of it like this—while printing "Good Morning: \nStudents", when Java encounters ‘G’, it
prints ‘G’ on the screen and when ‘o’, then ‘o’ and so on. Then when it encounters ‘\n’, it moves to a new line. And
the rest sentence is displayed in the new line.
Program 4 Write a program to demonstrate the use of \n.
1 class escapesequence_n
2 {
3 public static void main()
4 {
5 System.out.println("Good Morning:\nStudents");
6 }
7 }
You will get the following output:
Values and Types 57

