优快云新人入伙,请多关照!代码仅供参考!
切记不要白嫖哈!!!记得点赞o
其中的一些代码逻辑全是靠着自己在大乐透的往期中奖号码当中寻找的一些规律,并且这只是模仿大乐透的一点简单原理,希望各位童鞋不要使用这个计算出来的号码去买大乐透,买了不中你可别来找我啊!!!重要的事情加三个感叹号。
当然了,如果有大神能帮忙指出代码中的不足也是万分的感谢!!!
public static void main(String[] args) {
List<String> list = new ArrayList<>();
String theLotto = null ;
int w = 0;
do {
//前五位数
String [] arr = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21",
"22","23","24","25","26","27","28","29","30","31","32","33","34","35"};
//后两位数
String [] brr = {"01","02","03","04","05","06","07","08","09","10","11","12"};
//产生0-(arr.length-1)的整数值,也是数组的索引
int a1 = (int)(Math.random()*arr.length);
int a2 = (int)(Math.random()*arr.length);
int a3 = (int)(Math.random()*arr.length);
int a4 = (int)(Math.random()*arr.length);
int a5 = (int)(Math.random()*arr.length);
int b1 = (int)(Math.random()*brr.length);
int b2 = (int)(Math.random()*brr.length);
//保证前五位数的不同及升序,后两位数的不同及升序
if(a1!=a2 && a1!=a3 && a1!=a4 && a1!=a5 && a1<a2 && a1<a3 && a1<a4 && a1<a5 &&
a2!=a3 && a2!=a4 && a2!=a5 && a2<a3 && a2<a4 && a2<a5 &&
a3!=a4 && a3!=a5 && a3<a4 && a3<a5 &&
a4!=a5 && a4<a5
&& b1 < b2 ) {
//根据下标取出对应的值
theLotto = arr[a1]+" "+arr[a2]+" "+arr[a3]+" "+arr[a4]+" "+arr[a5]+" "+arr[b1]+" "+arr[b2];
//添加到list
list.add(theLotto);
w = w+1;
}
//在list集合当中增加一百条数据
}while (w < 100);
StringBuffer result = new StringBuffer();
int s = 0;
do {
//随机获取list集合中100条数据中的其中5条数据
String s1 = list.get((int)(1+Math.random()*(10-1+1)));
String s2 = list.get((int)(1+Math.random()*(10-1+1)));
String s3 = list.get((int)(1+Math.random()*(10-1+1)));
String s4 = list.get((int)(1+Math.random()*(10-1+1)));
String s5 = list.get((int)(1+Math.random()*(10-1+1)));
//判断五组数据不能相同
if(!s1.equals(s2) && !s1.equals(s3) && !s1.equals(s4) && !s1.equals(s5)){
if(!s2.equals(s3) && !s2.equals(s4) && !s2.equals(s5)){
if(!s3.equals(s4) && !s3.equals(s5)){
if(!s4.equals(s5)){
result.append(s1).append("\n")
.append(s2).append("\n")
.append(s3).append("\n")
.append(s4).append("\n")
.append(s5);
s = s+1;
}
}
}
}
}while (s<1);
System.out.println(result);
}