import java.util.*;

public class DoubleBallGenerator { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入购买的双色球注数:"); int count = input.nextInt(); for(int i=1; i<=count; i++){ List redBalls = generateRedBalls(); int blueBall = generateBlueBall(); System.out.print("第" + i + "注双色球号码为:"); for(int j=0; j<redBalls.size(); j++){ System.out.print(redBalls.get(j) + " "); } System.out.println("+ " + blueBall); } }

//生成6个红球
public static List<Integer> generateRedBalls(){
    List<Integer> redBalls = new ArrayList<Integer>();
    Random random = new Random();
    while(redBalls.size() < 6){
        int ball = random.nextInt(33) + 1;
        if(!redBalls.contains(ball)){
            redBalls.add(ball);
        }
    }
    Collections.sort(redBalls); //排序
    return redBalls;
}

//生成1个蓝球
public static int generateBlueBall(){
    Random random = new Random();
    int blueBall = random.nextInt(16) + 1;
    return blueBall;
}

}

双色球号码生成器 - 随机生成双色球号码

原文地址: https://www.cveoy.top/t/topic/n1AX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录