public static void main(String[] args) {
// TODO Auto-generated method stub
String[] str=xuanshu();
System.out.println(Arrays.toString(str));
}
public static String[] xuanshu(){
//定义双色球池
String[] chizi={"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"};
//存储选选好的球
String[] jieguo=new String[7];
//标记选到的球
boolean[] biaoji=new boolean[33];
//标记选的个数
int geshu=0;
//随机数生成器
Random r=new Random();
while(true){
//生成随机数
int a=r.nextInt(chizi.length);
//判断此数是否被选
//没选中则标记
if(!biaoji[a]){
biaoji[a]=true;
jieguo[geshu]=chizi[a];
geshu++;
}
//选满6个数则退出循环
if(geshu==6){
break;
}
}
//选蓝号
int b=r.nextInt(16);
//把蓝号放在最后位
jieguo[6]=chizi[b];
System.out.println(jieguo[6]);
//把前六个号码排序
Arrays.sort(jieguo,0,5);
return jieguo;
} |
|