Programming lists the full-character combination of a string with no repeating characters in the original string, for example:
The original string is "ABC", and all of the following combinations are printed:
"A" "B" "C"
"AB" "BC" "CA" "BA" "CB" "AC"
"ABC" "ACB" "BAC" "BCA" "Cab" "CBA"
Import Java.util.arraylist;import Java.util.list;public class Test {static char[] chars = "abc". ToCharArray ();p ublic static void Main (string[] args) {for (int i = 0; i < chars.length; i++) {//Get every character list<integer> list = new Array List<integer> (); List.add (i);p lay (list);}} Use recursion to add a character that does not exist in the list each time to the private static void play (List<integer> list) {print (list); for (int i = 0; i < chars.length ; i++) {if (!list.contains (i)) {list<integer> temp = new arraylist<integer> (list), Temp.add (i);p lay (temp);}} Print List contents private static void print (List<integer> list) {for (Integer i:list) System.out.print (Chars[i] + ""); System.out.println ();}}
Any combination of algorithm output string characters