Java Program to display double and single quote in a string

Java 8Object Oriented ProgrammingProgramming

The following are our strings with single and double quote.

String str1 = "This is Jack's mobile";
String str2 = "\"This is it\"!";

Above, for single quote, we have to mention it normally like.

This is Jack's mobile

However, for double quotes, use the following and add a slash in the beginning as well as at the end.

String str2 = "\"This is it\"!";

The following is an example.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      String str1 = "This is Jack's mobile";
      String str2 = "\"This is it\"!";
      System.out.println("Displaying Single Quote: "+str1);
      System.out.println("Displaying Double Quotes: "+str2);
   }
}

Output

Displaying Single Quote: This is Jack's mobile
Displaying Double Quotes: "This is it"!
raja
Published on 17-Dec-2018 11:24:37
Advertisements