如果给定N个不同的字符,将N个字符全排列,最终的结果将会有N!种。
import java.util.Scanner; import java.util.Vector; public class One{ public static int count = 0; private void full_Array(Vector<Character> sourse, Vector<Character> result){ if(sourse.size() == 0){ for(int i = 0; i< result.size(); i++){ System.out.print(result.elementAt(i)); } System.out.println(); count ++; return; } for(int i = 0; i < sourse.size(); i++){ Vector<Character> tsourse = new Vector<Character>(sourse); //元素可以重复使用,穷尽所有的可能性 Vector<Character> tresult = new Vector<Character>(result); tresult.add(tsourse.elementAt(i)); tsourse.remove(i); new One().full_Array(tsourse, tresult); } } public static void main(String[] args){ Vector<Character> sourse = new Vector<Character>(); Vector<Character> result = new Vector<Character>(); System.out.println("请输入元素个数"); Scanner sc = new Scanner(System.in); int num = sc.nextInt(); for(int i = 0; i < num; i++){ sourse.addElement((char) ('A' + i)); } new One().full_Array(sourse, result); System.out.println(count); } }