using System.Collections.Generic
using System.Textnamespace guan
{
class Program
{
static void Main(string[] args)
{
char a
Console.WriteLine("请输入一个字符:")
a =Convert.ToChar(Console.ReadLine())
if (a == 'a' || a == 'e' ||a == 'i' ||a == 'o' ||a == 'u')
Console.WriteLine("此字符是元音")
else
Console.WriteLine("此字符是音辅")
Console.Read()
}
}
}
以英文为例: A、E、I、O、U , 这五个字母是元音, 其它的 21个字母不就是辅音了吗。switch (chr){
case 'A','E','I','O','U':
print 'YES'
break
default:
print 'NO'
break
}
import java.util.Randompublic class VowelAndConsonants {
public static void main(String[] args){
//java随机类,用来生成种子数字
Random rand = new Random(47)
for(int i = 0i<100i++){
//产生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")
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)