您的位置:首页 > 其它

输出所有排列组合

2014-03-27 09:28 155 查看
package static1;
import java.util.Arrays;

public class Permutation {
public static void main(String[] args){
int[] array=new int[]{1, 2,3};
permute(array,0);
}

public static void permute(int a[], int s) {
if (s == a.length) {
System.out.println(Arrays.toString(a));
} else
for (int i = s; i < a.length; ++i) {
swap(a, s, i);
permute(a, s + 1);
swap(a, s, i);

}
}

private static void swap(int[] a,int s,int i) {
int t=a[s];
a[s]=a[i];
a[i]=t;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: