各位大虾帮我看下有什么好点的方法从33个数中选6组合,并放到一个数组中
各位大虾帮我看下有什么好点的方法从33个数中选6组合,并放到一个数组中
我这样程序运行起来太慢了,很郁闷啊,各位大虾指点下,有没有好一的方法啊!
ArrayList number = new ArrayList();
int[] allnumber = { 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 };
for (int f1 = 0; f1 < 33; f1++) {
for (int s2 = 0; s2 < 33 & s2 != f1; s2++) {
for (int t3 = 0; t3 < 33 & t3 != s2 & t3 != f1 & s2 < 33
& s2 != f1; t3++) {
for (int f4 = 0; f4 < 33 & f4 != t3 & f4 != s2 & f4 != f1
& t3 < 33 & t3 != s2 & t3 != f1; f4++) {
for (int f5 = 0; f5 < 33 & f5 != f4 & f5 != t3
& f5 != s2 & f5 != f1 & f4 < 33 & f4 != t3
& f4 != s2 & f4 != f1; f5++) {
for (int s6 = 0; s6 < 33 & s6 != f5 & s6 != f4
& s6 != t3 & s6 != s2 & s6 != f1; s6++) {
int xnumber[] = { allnumber[f1], allnumber[s2],
allnumber[t3], allnumber[f4],
allnumber[f5], allnumber[s6] };
for (int i = 0; i <1107568; i++) {
mapnum.put(i, xnumber);
}
}
}
}
}
}
}
------解决方案--------------------。。。 汗 不敢看。 没看懂你问的是啥哦 我理解能力不好 啥叫选6组合?
------解决方案--------------------int[] allnumber = { 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 };
ArrayList list=new ArrayList();
java.util.Random random=new java.util.Random();
while(true)
{
int i=random.nextInt(allnumber.length);
if(!list.contains(i))
{
list.add(i);
}
if(list.size()==6)
{
break;
}
}