java程序 判断一个字母是元音还是辅音

如题所述

import java.util.Random;;
public class VowelAndConsonants {
public static void main(String[] args){
//java随机类,用来生成种子数字
Random rand = new Random(47);
for(int i = 0; i<100; i++){
//产生0~26之间的一个值,再加上一个偏移量'a',即可产生小写字母
int c = rand.nextInt(26) + 'a';
System.out.print((char)c + ", " + c + ":");
switch(c){
//符合条件的case语句重叠在一起,形成多重匹配,判断是不是元音
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': System.out.println("Vowel");break;

//判断是不是半元音,同样用到了重叠case语句
case 'y':
case 'w': System.out.println("Sometimes is a vowel");break;
//不符合以上条件的则都是辅音
default:System.out.println("consonant");
}
}
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答