English

Explain the Escape Sequences in Java.

Advertisements

Question

Explain the Escape Sequences in Java.

Explain
Advertisements

Solution

In Java, Escape Sequences are special character combinations used to represent characters that cannot be directly typed or displayed in a string. An escape sequence begins with a backslash (\) followed by a character. These sequences are mainly used to format text and control the output of a program.

The commonly used escape sequences in Java are as follows:

Escape Sequence

Description

\n

It is used to move the cursor to a new line.

\t

It is used to insert a horizontal tab space.

\b

It represents a backspace character.

\r

It is used to move the cursor to the beginning of the current line.

\f

It represents a form feed character.

\'

It is used to represent a single quotation mark.

\"

It is used to represent a double quotation mark.

\\

It is used to represent a backslash character.

Example:

System.out.println("Hello\nJava");

Output:

Hello
Java
shaalaa.com
  Is there an error in this question or solution?
Chapter 5: Primitive Values, Wrapper Classes, Types and Casting - EXERCISE [Page 112]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 5 Primitive Values, Wrapper Classes, Types and Casting
EXERCISE | Q 11. | Page 112
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×