导航:首页 > 编程语言 > java随机抽取

java随机抽取

发布时间:2023-07-11 01:51:48

A. 请问用java从1-33个整数中随机抽取6个数字 且不重复 1-16随机抽取一个数,给小球

完整代码为:

public class Main {

public static void main(String[] args) {
int index = 1;
int[] redBalls = new int[6];

Random random = new Random();
boolean getMoreRed = true;
boolean getAgain;
System.out.println("开始抽取红球!");
while (getMoreRed) {
getAgain = false;
int red = random.nextInt(36) + 1;
System.out.print("本次抽取到的红球为:[" + red + "]!");
for (int i = 0; i < index; i++) {
if (redBalls[i] == red) {
System.out.print("重复抽取,将重新抽取红球");
getAgain = true;
break;
}
}
System.out.println("");
if (getAgain){
continue;
}
redBalls[index - 1] = red;
index++;
getMoreRed = index < 7;
}
System.out.println("抽取到的红球为:");
Arrays.sort(redBalls);
for (int redBall : redBalls) {
System.out.print(redBall + " ");
}

System.out.println(" 开始抽取蓝球!");
System.out.println("本次抽取到的蓝球为:[" + (random.nextInt(16) + 1) + "]!");
}
}

阅读全文

与java随机抽取相关的资料

热点内容
cmd命令结束进程 浏览:443
程序员逗比图片大全 浏览:512
免编程游戏引擎 浏览:364
微信应用锁加密 浏览:451
数字英雄对程序员的影响 浏览:761
程序员培训学校排名 浏览:586
oppo手机如何解开微信的加密 浏览:37
学校论文答辩源码 浏览:66
rp在单片机中 浏览:178
linux软件运行命令 浏览:354
stcid加密程序 浏览:139
把解压包子放到水里 浏览:286
phpmongodb连接池 浏览:945
日本解压捏泡泡纸 浏览:121
环保参比算法 浏览:413
解压中的删掉是什么意思 浏览:766
王牌竞速什么时候能停止维修服务器 浏览:488
pdf阅读器官方 浏览:88
程序员那么爱心 浏览:305
字符a经过md5加密 浏览:420