表示应该删除的令牌出现语法错误



我的源代码是:

System.out.print("Enter an Alphabet: ");
char ch = scan.next().charAt(0);
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println(+ch " is a vowel.");
break;
default:
System.out.println(+ch " is a consonant.");
}

但是它说它在";是元音";并且在";是一个辅音";。有人能告诉我我的代码出了什么问题吗?

我认为+在变量的错误一侧。

System.out.println(ch + " is a vowel.");
public static void main(String... args) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.print("Enter an Alphabet: ");
char ch = scan.next().charAt(0);
System.out.format("'%s' is a %s.", ch, isVowel(ch) ? "vowel" : "consonant");
}
public static boolean isVowel(char ch) {
ch = Character.toLowerCase(ch);
return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

最新更新