希望能帮到你:
- import java.util.Scanner;
- public class PaiLie
- {
- private int len;
- private char[] getRest(char[] arr,int i)
- {
- char[] rs=new char[arr.length-1];
- for(int j=0;j<i;j++)
- rs[j]=arr[j];
- for(int j=i+1;j<arr.length;j++)
- rs[j-1]=arr[j];
- return rs;
- }
-
- public void getResult_All(String content)
- {
- char[] arr=content.toCharArray();
- len=arr.length;
- PL_All("",arr,len);
-
- }
- private void swap(char[] arr,int i,int j)
- {
- if(i==j)
- return;
- char tmp=arr[i];
- arr[i]=arr[j];
- arr[j]=tmp;
- }
- private void PL_All(String pre,char[] arr,int length)
- {
- if(length<1)
- return;
-
- for(int i=0;i<length;i++)
- {
- char first=arr[i];
- swap(arr, i, length-1);
- PL_All(pre+first,arr,length-1);
- swap(arr, length-1,i);
- }
- }
-
- public static void main(String[] args)
- {
- Scanner scanner=new Scanner(System.in);
- System.out.println("please input:");
- String content=scanner.nextLine();
- PaiLie PL=new
- PaiLie ();
- PL.getResult_All(content);
- }
- }
复制代码
|