Java 程式,用來在字串中顯示雙引號和單引號


以下是用單引號和雙引號建立的字串。

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

上面,對於單引號,我們需要正常標明,如下。

This is Jack's mobile

但是,對於雙引號,需要使用以下方法,並且在開頭和結尾處新增斜槓。

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

以下是一個示例。

示例

 演示

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);
   }
}

輸出

Displaying Single Quote: This is Jack's mobile
Displaying Double Quotes: "This is it"!

更新日期:2020 年 6 月 27 日

5000+ 觀看

拉開你的職業生涯序幕

完成課程以獲得認證

開始
廣告
© . All rights reserved.