每日总结
今天通过对问题的分析及查找资料和解决方法,成功地解决了昨天程序出现的问题,
顺利完成教程的综合实例,
综合实例的代码如下:
import java.util.Arrays;
import java.util.Random;
public class Ball {
public static void main(String[] args) {
// TODO Auto-generated method stub
//存放1~33号数字
String[] num= {"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"};
//存放1~33号数字是否使用过
boolean[] used=new boolean[num.length];
//存放双色球
String[] balls=new String[6];
Random ran=new Random();
int i=0;
int index=0;
while(true)
{//随机生成数组下标
i=ran.nextInt(num.length);
if(used[i]) {
continue;
}
used[i]=true;
balls[index++]=num[i];//取出一个球
if(index==balls.length) {//检查是否满了
break;//退出循环
}
}
Arrays.sort(balls);
//加入蓝球
String[] newballs=new String[7];
for(int m=0;m<balls.length;m++) {
newballs[m]=balls[m];
}
newballs[newballs.length-1]=num[ran.nextInt(16)];
//打印随机生成的双色球
System.out.println("双色球:"+Arrays.toString(newballs));
}