- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
-
- public class pai {
- private static char[] is ;
- private static int total;
- private static int m;
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- List<Integer> iL = new ArrayList<Integer>();
- System.out.println("请输入一串字符");
- String next = sc.next();
- is = next.toCharArray();
- m=next.length();
- for (int i = 1; i <= m; i++) {
- new pai().plzh("", iL, i);
- System.out.println();
- }
- System.out.println("total : " + total);
- }
- private void plzh(String s, List<Integer> iL, int m) {
- if(m == 0) {
- System.out.print(s+"\t");
- total++;
- return;
- }
- List<Integer> iL2;
- for(int i = 0; i < is.length; i++) {
- iL2 = new ArrayList<Integer>();
- iL2.addAll(iL);
- if(!iL.contains(i)) {
- String str = s + is[i];
- iL2.add(i);
- plzh(str, iL2, m-1);
- }
- }
- }
- }
复制代码 网上找到的 稍作修改。
|