English

Explain the following with an example segment: Escape Character

Advertisements

Question

Explain the following with an example segment:

Escape Character

Code Writing
Explain
Advertisements

Solution

  • An Escape Character in Java is a backslash (\) used with another character to represent special characters that cannot be directly written in a string.
  • Escape sequences are used to insert special characters such as a new line (\n), tab space (\t) and double quotation marks (\").

Example Code Segment:

System.out.println("Hello\nWorld");
System.out.println("Java\tProgramming");
System.out.println("Welcome to \"Java\"");

Output:

Hello
World
Java Programming
Welcome to "Java"
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 131]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 29. (ii) | Page 131
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×