码迷,mamicode.com
首页 > 编程语言 > 详细

java 输入一个字符串,打印出该字符串中字符的所有排列

时间:2018-05-12 22:33:46      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:ring   can   scan   void   pre   class   输入   valueof   ==   

import java.util.Scanner;
  
public class Demo001 {
      
    public static void main(String[] args) {
        String str = "";
          
        Scanner scan = new Scanner(System.in);
          
        str = scan.nextLine();
          
        permutation(str.toCharArray(), 0);
    }
  
    public static void permutation(char[] str, int i) {
        if (i >= str.length)
            return;
        if (i == str.length - 1) {
            System.out.println(String.valueOf(str));
        } else {
            for (int j = i; j < str.length; j++) {
                char temp = str[j];
                str[j] = str[i];
                str[i] = temp;
  
                permutation(str, i + 1);
  
                temp = str[j];
                str[j] = str[i];
                str[i] = temp;
            }
        }
    }
  
}

  

java 输入一个字符串,打印出该字符串中字符的所有排列

标签:ring   can   scan   void   pre   class   输入   valueof   ==   

原文地址:https://www.cnblogs.com/gjack/p/9030031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!