1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public class Subsequence { public static void printAllSub(String str) { char[] chs = str.toCharArray(); process(chs, 0, ""); System.out.println(""); }
public static void process(char[] chs, int i, String pre) { if (i == chs.length) { if (!pre.equals("")) { System.out.println(pre); } return; } process(chs, i + 1, pre + String.valueOf(chs[i])); process(chs, i + 1, pre); }
public static void main(String[] args) { String test = "abc"; printAllSub(test); } }
|