我想打印此標誌/\
但在編譯器上,我認爲一切正常,但無法編譯。錯誤出現爲無法編譯我的代碼
leets.java:13: error: unclosed string literal
System.out.printf ("%s /\",ch);
^
leets.java:13: error: ';' expected
System.out.printf ("%s /\",ch);
^
2 errors
我的代碼如下。
import java.util.Scanner;
public class switchDemo2
{
public static void main (String args[])
{
Scanner i = new Scanner (System.in);
System.out.print ("Enter a character to test: ");
char ch;
ch = i.next().charAt(0);
switch (ch)
{
case 'A': case 'a':
System.out.printf ("%s /\",ch);
break;
case 'B': case 'b':
System.out.printf ("%s 13",ch);
break;
case 'C': case 'c':
System.out.printf ("%s)",ch);
break;
case 'D': case 'd':
System.out.printf ("%s 1)",ch);
break;
case 'E': case 'e':
System.out.printf ("%s 3",ch);
break;
case 'F': case 'f':
System.out.printf ("%s 1=",ch);
break;
default:
System.out.printf ("%s not a lowercase vowel\n",ch);
}
}
你需要閱讀有關使用Java – jondinham
文本字符串轉義序列,正如其他人告訴你,那就是缺少一個轉義序列,它不是一個很好的做法來命名從較小的案例開始。將它重命名爲SwitchDemo2 :) – DDK