java实现: 随机生成小写字母,并判断是元音还是辅音
用switch进行判断,然后把switch放入for循环
package com.word.word;
//随机生成小写字母,并判断是元音还是辅音
public class VowelsAndConsonants {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
int c = 'a' + (int) (Math.random() * 26);
System.out.print("字母 " + (char) c);
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println(" 是元音");
break;
case 'y':
case 'w':
System.out.println("是半元音");
break;
default:
System.out.println("是辅音");
}
}
}
}
结果: