本帖最后由 迦罗叶 于 2014-2-21 12:28 编辑
//随机获取33位中的6位
public static String[] base()
{
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"};
boolean[] arr = new boolean[33];
//获取红球
String[] redBase = new String[6];
int x=0;
do
{
Random r = new Random();
int temp = r.nextInt(num.length);//从0<=temp<num.length(33)中随机抽取一个数
//请问一下,下面的if(!arr[temp])中的!arr[temp]结果就是true,为什么我改成true就不行呢
if(!arr[temp])
{
arr[temp] = true;
redBase[x] = num[temp];
x++;
}
}
while (x<6);
return redBase;
}
} |