彩票生成器--36选7 无重复(案例)

package suijishu;

import java.util.Random;

public class suijishu{

public static void main(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++){
            if(temp == caiPiao[j]){ //检查是否有重复,有重复就记录chongFuCiShu++;
                chongFuCiShu++;
            }
        }
        
        if(chongFuCiShu == 0){
            caiPiao[i]=temp;
        }
        else{
            i--;
        }
        //System.out.print(temp+"\t");
        for(int l =0;l<caiPiao.length;l++)
        {//显示
        
    }
        System.out.print(caiPiao[i]+"\t");}
}    
}

posted @ 2015-12-08 11:43  秦萧不再  阅读(601)  评论(0编辑  收藏  举报