java随机生成双色球幸运号码
时间: 2023-11-29 13:45:37 浏览: 176
java随机生成8位数授权码的实例
5星 · 资源好评率100%
以下是Java随机生成双色球幸运号码的代码示例:
```java
import java.util.Arrays;
import java.util.Random;
public class DoubleColorBall {
public static void main(String[] args) {
int[] redBalls = new int[33];
for (int i = 0; i < redBalls.length; i++) {
redBalls[i] = i + 1;
}
int[] selectedRedBalls = new int[6];
Random random = new Random();
for (int i = 0; i < selectedRedBalls.length; i++) {
int index = random.nextInt(redBalls.length - i);
selectedRedBalls[i] = redBalls[index];
redBalls[index] = redBalls[redBalls.length - i - 1];
}
Arrays.sort(selectedRedBalls);
int selectedBlueBall = random.nextInt(16) + 1;
System.out.println("红球:" + Arrays.toString(selectedRedBalls));
System.out.println("蓝球:" + selectedBlueBall);
}
}
```
阅读全文