36选7 java代码

 1     public static void main(String[] args)
 2     {
 3         //36选7
 4         int[] caiPiao  = new int[7];
 5         Random rand = new Random();
 6         
 7         //生成
 8         for(int i=0;i<7;i++)        //生成7个随机数。i代表正在生成第几个数
 9         {
10             int temp = rand.nextInt(36);    
11             temp++;                    //生成随机数
12             //解决重复问题
13             int chongFuCiShu = 0;    //检索数组,记录重复次数
14             for(int j=0;j<7;j++){    //检查是否有重复,有重复就记录chongFuCiShu++;
15                 if(temp == caiPiao[j]){
16                     chongFuCiShu++;
17                 }
18             }
19             
20             if(chongFuCiShu == 0){
21                 caiPiao[i]=temp;
22             }
23             else{
24                 i--;
25             }
26             //System.out.print(temp+"	");
27             
28         }
29         //显示
30         for(int i=0;i<caiPiao.length;i++)
31         {
32             System.out.print(caiPiao[i]+"	");
33         }
34         
35     }
36选7
原文地址:https://www.cnblogs.com/zjy954/p/5026154.html