36选7

package test;

import java.util.Random;

public class SSQ {

public static void main(String[] args) {
        
        int[] cai = new int[7];
        Random rand = new Random();
        
        
        //生成
        
        for(int i = 0;i < 7;i++)           //循环7次,生成7个随机数
        {
            int temp  = rand.nextInt(36);
            temp ++;             //生成随机数
            
            // 解决重复问题
            int chf = 0;//检索数组,记录重复次数
            
            for(int j = 0;j<7;j++){//检查是否重复,有重复记录chf++
                
                if (temp == cai[j]){
                    chf++;
                }
                
                
                
            }
            if(chf == 0){
                cai[i] = temp;
            }
            else{
                i--;
                
            }
            
            
            //System.out.print(temp + "	");
            
            
        }
        
        //显示
        for(int i = 0;i<cai.length;i++){
            System.out.print(cai[i] + "	");
        }


        
    
        
        
        
        
        
        
        // TODO 自动生成的方法存根

    }

    
    

}
原文地址:https://www.cnblogs.com/WY404683569/p/5028081.html