直接递归就可以了哈!
- package com.itheima.bbs;
- public class StringTest {
-
- public static String str = "abc";
-
- public static void main(String[] args) {
-
- show(0, new String());
-
- }
-
- // 递归
-
- public static void show(int current_recur, String temp) {
-
- if (current_recur < str.length()) {
-
- for (int i = 0; i < str.length(); i++) {
-
- if (!(temp.contains(str.substring(i, i + 1)))) {
-
- System.out.print("'"+temp + str.substring(i, i + 1)+"'" + " ");
-
- show(current_recur + 1,
- new String(temp + str.substring(i, i + 1)));
- }
- }
- }
- }
-
-
- }
复制代码 |