import java.util.*;
public class DoubleColorBall {
public static void main(String[] args) {
List<Integer> redBalls = getredBalls();
int blueBall = getBlueBall();
// 格式化输出开奖结果
System.out.print("红球:");
for (int ball : redBalls) {
System.out.printf("%02d ", ball); // 两位数格式输出
}
System.out.println(); // 换行
System.out.printf("蓝球:%02d", blueBall);
}
static List<Integer> getredBalls() {
// 1. 创建1-33的数字池
List<Integer> redBallPool = new ArrayList<>(33);
for (int i = 1; i <= 33; i++) {
redBallPool.add(i);
}
// 2. 洗牌打乱顺序
Collections.shuffle(redBallPool);
// 3. 取前6个球并排序,生成红球(1-33选6个不重复)
List<Integer> redBalls = new ArrayList<>(6);
for (int i = 0; i < 6; i++) {
redBalls.add(redBallPool.get(i));
}
Collections.sort(redBalls);
return redBalls;
}
static int getBlueBall() {
// 生成蓝球(1-16选1个)
return new Random().nextInt(16) + 1;
}
}