Java Program to display double and single quote in a string


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"!

Updated on: 27-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements