1. 程式人生 > >雙色球--最多2個號碼相同的內幕

雙色球--最多2個號碼相同的內幕

str 數組 標題 string 內幕 exti continue print use

雖然是標題黨,但是功能卻是能讓雙色球最多只有2個球號碼相同,不知道沒中過雙色球或者只有2個雙色球的小夥伴是不是買了假的雙色球了啊。

代碼如下:
class Doubleball{
public static void main(String[] args){
            String pool[]={"01","02","03","04","05","06"
         ,"07","08","09","10","11","12","13","14",
        "15","16","17","18","19","20","21","22",
        "23","24","25","26","27","28","29","30",
        "31","32","33"};
                Random rad=new Random();
                String str=new String[6];
                int index=0;
                int i=0
                boolean used[]=new boolean[pool.length];
                while (index<str.length){
                                    i=rad.nextInt(pool.length);
                                    if(used[i]){
                                                    continue;
                                    }
                                    index++;
                                    str[index]=pool[i];
                                    used[i]=ture;
                }
                Arrays.Sort(str);
                str=Arrays.copyOf(str,str.length+1);
                str[str.length-1]=pool[rad.nextInt(15)];
                System.out.println(Arrays.toString(str));
}
}

used數組已經將前6個中相同的跳過了,因此最多只能出現一個號碼相同最終。

雙色球--最多2個號碼相同的內幕