java实现彩票复试选号的方法

来源:百度知道 编辑:UC知道 时间:2024/05/27 23:52:29
比如:从1-33,我选出4,6,14,17,18,23,26,28这8个数,目的是要从这八个数中选出所有可能的 6个数组合,不重复,java实现

我只有39分,想再多给也没有了。。。谢谢了。。。

楼上的好复杂-_-!
public class findComb{
static int[] a=new int[100];
public static void main(String str[]){

int[] n={4,6,14,17,18,23,26,28};
int length=n.length;
int r=6;
a[0]=r;
comb(n,length-1,r);
}
public static void comb(int[] n,int length,int r){
int i=0;
int j=0;
for(i=length;i>=r-1;i--){
a[r]=n[i];
if(r>1)
comb(n,i-1,r-1);
else{
for(j=a[0];j>0;j--)
System.out.print(a[j]+"、");
System.out.println();
}
}
}
}

这个是挺麻烦,

不错,递归,我喜欢,一楼让给你了