令牌上的语法错误,表示应该删除它

3phpmpom  于 2021-07-05  发布在  Java
关注(0)|答案(2)|浏览(318)

**结案。**此问题不可复制或由打字错误引起。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

上个月关门了。
改进这个问题
我的源代码是:

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.");
}

但它说它在“是元音”和“是辅音”上有语法错误。有人能告诉我代码有什么问题吗?

xghobddn

xghobddn1#

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';
}
g9icjywg

g9icjywg2#

这个 + 在你的变量的错误的一边。

System.out.println(ch + " is a vowel.");

相关问题