import java.util.*;
public class Permutations {
public static int maxnum=10;//总数
public static int neednum=10;//需要选择的个数
public static int a[];
public static int b[];
public static void apermutation(int aindex,int bindex){
if(bindex==neednum){
for(int i=0;i<neednum;i++)
System.out.print(b[i]+" ");
System.out.println("");
return ;
}
if((maxnum-aindex)<(neednum-bindex))//如果剩下的数的个数小于还要选的个数
return;
for(int i=aindex;i<maxnum;++i){
b[bindex]=a[i];
apermutation(i+1,bindex+1);
}
}
public static void main(String[] args) {
a=new int[]{1,2,3,4,5};
b=new int[3];
maxnum=5;
neednum=3;
apermutation(0, 0);
}
}
输出为:
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5