- public class test {
-
- static int c = 0;
-
- public static void main(String[] args) {
- String s = "abcd";
- printAllArray(s);
- }
-
- private static void printAllArray(String s) {
- printAllArray(s, "");
- }
-
- private static void printAllArray(String s, String n) {
- if (s.length() == 0) {
- System.out.println(n + " --- " + ++c);
- } else {
- for (int i = 0; i < s.length(); ++i) {
- printAllArray(s.substring(1), n + s.charAt(0));
- s = s.substring(1) + s.charAt(0);
- }
- }
- }
- }
复制代码 |