public static void main(String[] args) { String strYuanyin = "aeiou"; String strFuyin = "bcdfghjklmnpqrstvwxyz"; char[] yuanyin = strYuanyin.toCharArray(); char[] fuyin = strFuyin.toCharArray(); System.out.println("下面是2个元音字母:"); int times = 0; while (times < 2) { int i; do { i = new Random().nextInt(5); } while (yuanyin[i] == '0'); System.out.print(yuanyin[i] + " "); // 使用过的标记为0 yuanyin[i] = '0'; times++; }
System.out.println();
System.out.println("下面是8个辅音字母"); times = 0; while (times < 8) { int i; do { i = new Random().nextInt(21); } while (fuyin[i] == '0'); System.out.print(fuyin[i] + " "); // 使用过的标记为0 fuyin[i] = '0'; times++; } } }