- package com.itheima;
- /*
- * 编程列出一个字符串的全字符组合情况,原始字符串中没有重复字符,例如:
- * 原始字符串是"abc",打印得到下列所有组合情况:
- * "a" "b" "c"
- * "ab" "bc" "ca" "ba" "cb" "ac"
- * "abc" "acb" "bac" "bca" "cab" "cba"
- */
- public class Test8 {
- 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)));
- }
- }
- }
- }
- }
复制代码
|
|