java简单的双色球摇号程序

 1 import java.util.HashSet;
 2 import java.util.Random;
 3 import java.util.Set;
 4 
 5 
 6 /**
 7  * LotteryClient
 8  * @author hm.zhou
 9  *
10  */
11 public class LotteryClient {
12     
13     public static void main(String[] args) {
14         doStart(10);
15     }
16     
17     
18     //随机产生几组号码
19     private static void doStart(int times){
20         for (int i = 0; i < times; i++) {
21             productNum();
22         }
23         
24     }
25     //随机摇出一个号
26     private static void productNum(){
27         Set<String> redNums = new HashSet<String>();
28         //产生红球
29         while(redNums.size()<6){
30             redNums.add(getNum(34));
31         }
32         for(String redNum:redNums){
33             System.out.print(redNum+" ");
34         }
35         System.out.print("+ ");
36         //产生蓝球
37         System.out.print(getNum(17) + "\n");
38         
39     }
40     //随机产生数
41     public static String getNum(int maxNum){
42         Random random = new Random();
43         int blueNum = random.nextInt(maxNum);//随机产生一个整数
44         if(blueNum==0)
45             return getNum(maxNum);//去除0
46         if(blueNum<10)
47             return "0" +blueNum;
48         return String.valueOf(blueNum);
49         
50     }
51     
52     
53     
54 
55 }

 

posted @ 2013-07-11 13:49  清晨の雨露  阅读(4547)  评论(0编辑  收藏  举报