引用和意图

问题描述

以下代码输出应如下所示:

The following is a quote:
"Now is the time
for all "good" men
to come to the
aid of their party"
public class Quote { 
    public static void main(String arg[]) {
        System.out.println("The following is a quote:\n\"Now is the time\nfor all\"good\"men\ntocome to the\naid of their party\"");
    }
}

解决方法

您可以这样做-

System.out.println("The following is a quote:\n"+"now is the time\nfor all \"good\" men \nto come to the\naid of their party");

输出:

The following is a quote:
now is the time
for all "good" men
to come to the
aid of their party

System.out.println("The following is a quote:\nnow is the time for all \"good\" men to come to the aid of their party");

输出-

The following is a quote:
now is the time for all "good" men to come to the aid of their party

在Java中,您可以使用\

转义报价

示例-System.out.println("This is \"10\"");

要打印",请使用\之类的\"

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...