在英语字母中,字符“ a”,“ e”,“ i”,“ o”,“ u”是元音,其余字母是辅音。查找给定字母是元音还是辅音。
使用循环和或运算符验证给定字符是'a'还是'e'或'i'或'o'或'u',否则它是辅音。
import java.util.Scanner;
public class VowelOrConsonant {
public static void main(String args[]){
System.out.println("输入字符:");
Scanner sc = new Scanner(System.in);
char ch = sc.next().charAt(0);
if(ch == 'a'|| ch == 'e'|| ch == 'i' ||ch == 'o' ||ch == 'u'||ch == ' '){
System.out.println("Given character is an vowel");
}else{
System.out.println("Given character is a consonant");
}
}
}输出结果
输入字符: a Given character is an vowel 输入字符: l Given character is a consonant