public static char[] generate(int n){//创建字母表的字符数组char [] chs = {'A','B','C','D','E','F','G','H'};//标志位对应每一个字符boolean [] used = new boolean[chs.length];int i;//用来存放选中的字符的数组char [] answer = new char [n];int index = 0;Random random =new Random();/** * 循环随机从字符表中选出5个字符 */do {i = random.nextInt(chs.length);//判断标志位的真假if(used[i]){continue;}answer[index++] = chs [i]; //经典数组下标移动语句used[i]=true;}while(index!=n);return answer;}
猜字符游戏
最新推荐文章于 2020-09-30 18:16:07 发布