3 回答
TA贡献1775条经验 获得超11个赞
它给出了非法转义字符,因为不必转义“(”和“{”。
System.out.println("A well-formed Java program has");
System.out.println("a main method with { and }");
System.out.println("braces.");
System.out.println();
System.out.println("A System.out.println statement");
System.out.println("has ( and ) and usually a");
System.out.println("String that starts and ends");
System.out.println("with a \" character");
System.out.println("(but we type \\\" instead!");
上面的代码按预期编译和工作。
可用作转义序列的字符有:
\t Insert a tab in the text at this point.
\b Insert a backspace in the text at this point.
\n Insert a newline in the text at this point.
\r Insert a carriage return in the text at this point.
\f Insert a formfeed in the text at this point.
\' Insert a single quote character in the text at this point.
\" Insert a double quote character in the text at this point.
\\ Insert a backslash character in the text at this point.
您可以在此处找到 Java 8 的文档:https://docs.oracle.com/javase/tutorial/java/data/characters.html
TA贡献1796条经验 获得超10个赞
public class WellFormed {
public static void main(String[] arga) {
System.out.println("A well-formed Java program has");
System.out.println("a main method with \\{ and \\}");
System.out.println("braces.");
System.out.println();
System.out.println("A System.out.println statement");
System.out.println("has \\( and \\) and usually a");
System.out.println("String that starts and ends");
System.out.println("with a \" character");
System.out.println("(but we type \\\" instead!");
}
}
添加回答
举报