求java程序随机生成彩票双色球

1-随机产生10000张双色球彩票
2-彩票的红球(前6位号码)要求按升序排列,与篮球(第7位的特码)用“+”连接
3-将生成的10000彩票写入到*.txt文件,并输出显示生成10000张彩票所花费的时间
4-系统随机生成中奖号码,输出显示
5-检查10000张彩票中,是否有中奖的彩票。如果中奖给出提示

import java.util.ArrayList;
import 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 = 0; n < 注数; 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 = 0; j < 32; j++)
list1.add(j + 1);
for (int i = 0; i < 16; i++)
list2.add(i + 1);

// 红球
System.out.print("红球:");
for (int k = 0; k < 6; k++) {
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;
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答