一个排列问题
从1~12中选出6个数字排列,如2 3 8 5 12 6,用java怎样实现列举出所有的排列?有朋友说用hash map,但是有没有更便捷更灵活的方法?比如说可以任选数字的个数,求指教
------最佳解决方案--------------------package exec.basic;
public class Paixu {
	public static void main(String[] args) throws Exception {
		char[] para = {1,2,3,4,5,6,7,8,9}; 
		for(int i=0;i<para.length;i++) 
			para[i]+=48;
		paixu(para,para.length,0);
	}
	private static void paixu(char[] array, int n, int k) {
		if (n == k) {
			char[] out = new char[n];
			for (int i = 0; i < array.length; i++) {
				out[i] = array[i];
			}
			System.out.println(new String(out));
		} else {
			for (int i = k; i < n; i++) {
				swap(array, k, i);
				paixu(array, n, k + 1);
				swap(array, i, k);
			}
		}
	}
	private static void swap(char[] a, int x, int y) {
		char temp = a[x];
		a[x] = a[y];
		a[y] = temp;
	}
}
------其他解决方案--------------------这里是我之前写的排列组合工具类:
http://blog.csdn.net/raistlic/article/details/7844812
前面有用法的代码示例,后面有源代码。
------其他解决方案--------------------多谢LS两位哈!