1-36随机生成6个不重复的数

 1 import java.util.Random;
 2 
 3 public class Homework0511 {
 4 
 5     public static void main(String[] args) {
 6         // TODO 自动生成的方法存根
 7 
 8         //抽奖  1-36 不重复  6个
 9         
10         Random rand=new Random();
11         int arr[]=new int[6];
12         for(int i=0;i<6;i++)
13         {
14             arr[i]=rand.nextInt(36);
15             for(int j=0;j<i;j++)
16             {
17             if(arr[i]==arr[j])
18             {
19                 i--;
20                 break;
21             }
22             }
23             
24             
25         }
26         for(int i=0;i<6;i++)
27         {
28             System.out.println(arr[i]+1);    
29         }
30         
31         
32         
33         
34     }
35 
36 }

运行结果:

posted @ 2016-05-11 11:35  鱼在我这里  阅读(980)  评论(0编辑  收藏  举报