package shiti1013;
import java.util.ArrayList;
import java.util.Scanner;
public class 字符所有组合 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串");
String line = sc.nextLine();
char[] c = line.toCharArray();
get(c);
}
public static void get(char[] c) {
//System.out.println(c.length);
ArrayList<String> list = new ArrayList<>();
ArrayList<String> list1 = new ArrayList<>();
int count = 1;
for (int i = 0; i < c.length; i++) {
System.out.print(c[i]+" ");
String x = c[i]+"";
list.add(x);
}
count++;
System.out.println();
System.out.println(list);
while(count<=c.length){
System.out.println(count);
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < c.length; j++) {
if(!(list.get(i).contains(c[j]+""))){
String x = list.get(i)+""+c[j];
System.out.print(x+" ");
list1.add(x);
//System.out.println(list1);
}
}
}
list.clear();
list.addAll(list1);
list1.clear();
System.out.println();
count++;
}
}
}
|
|