Possible Duplicate:
How do I make a string with a " character in it? (Java)

I am having trouble printing a string like this in java System.out.println("this is a "test""); How can I go about this?

有帮助吗?

解决方案

This is what you are looking for:

System.out.println("this is a \"test\"");

The \ is called the escape character.

It is used to embed special characters into a String literal.

\n = newline

\t = tab

\f = form feed

\r = carriage return

\" = double quote

\\ = backslash

this is just a few of the special characters you can insert with an escape sequence.

其他提示

The way you escape special characters in Java is using \. E.g. this ("\\") is how you return \ and this ("\"") is how you return ".

This is how you may implement your example:

System.out.println("this is a \"test\"");

escape the quote

System.out.println("this is a \"test\"");

You must escape the " characters in Java

System.out.println( "this is a \"test\"");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top