public class Shuangseqiu {

    public static void main2222(String[] args)
    {
        //36选7
        int[] caiPiao  = new int[7];
        Random rand = new Random();
        
        //生成
        for(int i=0;i<7;i++)        //生成7个随机数。i代表正在生成第几个数
        {
            int temp = rand.nextInt(36);    
            temp++;                    //生成随机数
            //解决重复问题
            int chongFuCiShu = 0;    //检索数组,记录重复次数
            for(int j=0;j<7;j++){    //检查是否有重复,有重复就记录chongFuCiShu++;
                if(temp == caiPiao[j]){
                    chongFuCiShu++;
                }
            }
            
            if(chongFuCiShu == 0){
                caiPiao[i]=temp;
            }
            else{
                i--;
            }
            //System.out.print(temp+"\t");
            
        }
        //显示
        for(int i=0;i<caiPiao.length;i++)
        {
            System.out.print(caiPiao[i]+"\t");
        }
        
    }

 

posted on 2015-12-08 08:27  一念了了  阅读(313)  评论(0编辑  收藏  举报