日期:2014-05-18 浏览次数:20759 次
package day04;
import java.util.Arrays;
import java.util.Random;
public class doubleBallDemo {
public static void main(String[] args) {
System.out.println(create());
}
public static String create(){
int[] redPool=new int[]{1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,21,22,
23,24,25,26,27,28,29,30,31,32,33};
int[] bluePool=new int[]
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
boolean[] used=new boolean[33];
int[] reds=new int[6];
String[] balls=new String[7];
Random r=new Random();
int i=0,j=0,idx=0;
for(i=0;i<reds.length;i++){
do{
j=r.nextInt(redPool.length);
if(used[j]!=true){
used[j]=true;
reds[i]=redPool[j];
idx++;
}
}while(idx==6);
}
Arrays.sort(reds);
System.out.println(Arrays.toString(reds));
System.arraycopy(reds,0,balls,0,6);
return Arrays.toString(balls);
}
}