怎么用Java random 输出 2个元音字母,八个辅音字母

对不起,因为本人是初者, 没有悬赏分了,拜托各位高手帮帮我吧
最新回答
玩贴吧的好菇凉

2024-11-04 15:45:19

public class YuanyinFuyin {

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++;
}
}
}