public class VowelsAndConsonants {
public static void main(String[] args) {
for (int i =0 ; i < 100 ; i++ ) {
char c = (char)(Math.random()*26+ 'a');
switch(c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':System.out.println("Vowels");
break;
case'y':
case'w':
System.out.println("sometimes is Vowels");
break;
default:System.out.println("Consonants");
}
}
}
}
注意点:1、switch case的使用
2、case 中的break的使用
3、char的加减法
错误:char c = (char) (Math.random() * 26) + 'a';