java简单的双色球摇号程序

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * 
 */

/**
 * LotteryClient
 * @author hm.zhou
 *
 */
public class LotteryClient {
    
    public static void main(String[] args) {
        doStart(10);
    }
    
    
    //随机产生几组号码
    private static void doStart(int times){
        for (int i = 0; i < times; i++) {
            productNum();
        }
        
    }
    //随机摇出一个号
    private static void productNum(){
        Set<String> redNums = new HashSet<String>();
        //产生红球
        while(redNums.size()<6){
            redNums.add(getNum(34));
        }
        for(String redNum:redNums){
            System.out.print(redNum+" ");
        }
        System.out.print("+ ");
        //产生蓝球
        System.out.print(getNum(17) + "\n");
        
    }
    //随机产生数
    public static String getNum(int maxNum){
        Random random = new Random();
        int blueNum = random.nextInt(maxNum);//随机产生一个整数
        if(blueNum==0)
            return getNum(maxNum);//去除0
        if(blueNum<10)
            return "0" +blueNum;
        return String.valueOf(blueNum);
        
    }
    
    
    

}

 

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