黑马程序员技术交流社区
标题:
机选双色球代码
[打印本页]
作者:
木头人之死
时间:
2015-7-9 18:15
标题:
机选双色球代码
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;
}
作者:
Miss.H
时间:
2015-7-9 18:22
额,完全看不懂啊,大神 还没学到这呢
作者:
进军黑马
时间:
2015-7-9 19:49
赞一个
作者:
路途
时间:
2015-7-9 19:51
赞一个,混混分..
作者:
jiangyu
时间:
2017-1-19 00:19
学习中!!!!!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2