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("是辅音");
            }
        }
    }
}

结果:
java实现:随机生成小写字母,并判断是元音还是辅音

相关文章:

  • 2021-10-11
  • 2022-12-23
  • 2021-10-26
  • 2021-05-25
  • 2021-05-12
猜你喜欢
  • 2021-09-20
  • 2021-10-19
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案