int[] red=new int[7]
int blue=0
for(int i=0i<7i=i+1){
red[i]=getRandom(33)
//判断重复
while(true){
boolean needcheck=false
for(int k=0k<ik=k+1) { if(red[i]==red[k]){ needcheck=true}}
if(needcheck){red[i]=red[i]+1if(red[i]==34){red[i]=1}}else{break}
}
//判断重圆旦复结束
}
//红球赋值结搏仔束
blue=getRandom(16)
System.out.println("生成的基腔汪红球为:"+ red[0]+red[1]+red[2]+red[3]+red[4]+red[5]+red[6])
System.out.println("生成的蓝球为:"+ )
}
public int getRandom(int Max){
return Math.floor(Math.random()*33)+1
}
import java.util.ArrayListimport java.util.Arrays
import java.util.Random
public class Main {
static Random r = new Random()
public static void main(String[] args) {
System.out.println("---------500W 我来啦----------")
int 注数 = 10000
for (int n = 0n <注数冲棚扰n++) {
摇奖()
}
System.out.println("---------500W 我来啦----------")
}
public static void 摇奖(){
//红球是1-32 篮球是1-16
ArrayList<Integer>list1 = new ArrayList<Integer>()
ArrayList<Integer>list2 = new ArrayList<Integer>散旦()
int[] redBalls = new int[6]
for (int j = 0j <32j++)
list1.add(j + 1)
for (int i = 0i <16i++)
list2.add(i + 1)
// 红球
System.out.print("红球:")
for (int k = 0k <6k++) {
int indexRed = r.nextInt(list1.size())
redBalls[k]=list1.get(indexRed)
list1.remove(indexRed)
}
Arrays.sort(redBalls)//和帆排序后打出红球
for(int s = 0 s <redBalls.length s++){
System.out.print(getRedBall(redBalls[s]) + " ")
}
int indexBlue = r.nextInt(list2.size())
System.out.println("蓝球:" + getRedBall(list2.get(indexBlue))+"")
}
public static String getRedBall(Integer a){
String b = ""
if (a<10) b = "0"+a+""
else b = a.toString()
return b
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)