码迷,mamicode.com
首页 > 其他好文 > 详细

双色球--最多2个号码相同的内幕

时间:2018-01-30 00:20:43      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:int   pool   ring   out   sort   print   system   ext   标题   

虽然是标题党,但是功能却是能让双色球最多只有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个号码相同的内幕

标签:int   pool   ring   out   sort   print   system   ext   标题   

原文地址:http://blog.51cto.com/10972685/2066603

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!