Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中打印双引号(“双引号”),其中参数用于打印值?_Java - Fatal编程技术网

如何在java中打印双引号(“双引号”),其中参数用于打印值?

如何在java中打印双引号(“双引号”),其中参数用于打印值?,java,Java,下面是我的代码: String str = "something"; char ch = 'e'; int noOfOcc = 1; System.out.println("No of occurrences of '"+ch+"' in "+str+" is "+noOfOcc); 预期产出应如下所示: No of occurrences of 'e' in "something" is 1 我怎么能用双引号把它打印出来?我需要在System.out.println()中使用变量的这种情况

下面是我的代码:

String str = "something";
char ch = 'e';
int noOfOcc = 1;
System.out.println("No of occurrences of '"+ch+"' in "+str+" is "+noOfOcc);
预期产出应如下所示:

No of occurrences of 'e' in "something" is 1
我怎么能用双引号把它打印出来?我需要在System.out.println()中使用变量的这种情况的解决方案;。我需要双引号中该变量的值。

使用
\“
对其进行转义,以便编译器知道不要将您的
视为用以下方式来划分
字符串的开始或结束:

System.out.println("No of occurrences of '"+ch+"' in \""+str+"\" is "+noOfOcc);
反斜杠作为转义序列打印双引号。

编译器不会解释斜杠符号后的字符。

使用反斜杠转义双引号System.out.println(“在\''+str+'\'+'中'+ch+'的出现次数为'+noOfOcc”);谢谢。这对我有用。