Computer Science, asked by lithaansh, 6 months ago

write a Java program for each of the escape sequences(/n,/t and/")​

Answers

Answered by RAAZ34
1

Answer:

Explanation:

Escape Sequences in Java

Last Updated: 29-04-2020

A character with a backslash (\) just before it is an escape sequence or escape character. We use escape characters to perform some specific task. The total number of escape sequences or escape characters in Java is 8. Each escape character is a valid character literal.

The list of Java escape sequences:

Why will we need Escape sequence?

Suppose we would like to run the subsequent java code:

filter_none

edit

play_arrow

brightness_4

public class Test {  

   public static void main(String[] args)  

   {  

       System.out.println("Hi geek, welcome to " GeeksforGeeks ".");  

   }  

}  

This code gives a compile time error as :

prog.java:3: error: ')' expected

   System.out.println("Hi geek, welcome to "GeeksforGeeks".");

                                            ^

prog.java:3: error: not a statement

   System.out.println("Hi geek, welcome to "GeeksforGeeks".");

                                                         ^

prog.java:3: error: ';' expected

   System.out.println("Hi geek, welcome to "GeeksforGeeks".");

                                                            ^

3 errors

This happened because the compiler expects nothing but only strings inside the quotation mark but when the compiler found a quotation mark, it expects another quotation mark in the near future (the closing one) and between them, the string of text should be created. During this case, the quotation marks of the word “GeeksforGeeks” gets nested(inside another quotation marks). Once the compiler reaches here, the compiler gets confused. According to the rule, the quotation mark suggests the compiler for creating a string but the compiler was busy with doing that thing previously and the code gives us a compile-time error.

So we should provide proper instructions to the compiler about the quotation mark. i.e, when a quotation is used for creating a string(as a command) and when it is a character itself (the part of the output string).

Similar sorts of confusion arise with other characters also(like- backslashes(), single and double quotation mark (‘, ”)) and these also provide a compile-time error in every case. For Solving these sorts of issues we have to use the java character escaping.

Answered by arahansingh742
0

Answer:

I don't no sir

Explanation:

mark as brainlist

Similar questions