*生成器--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+"	");
        for(int l =0;l<caiPiao.length;l++)
        {//显示
        
    }
        System.out.print(caiPiao[i]+"	");}
}    
}

原文地址:https://www.cnblogs.com/0927wyj/p/5028625.html