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.