- import java.io.*;
- import java.lang.reflect.Array;
- public class Java_CH8_HW2
- {
-
- public static void main(String[] args)
- {
- // TODO 自動產生的方法 Stub
- char byte1[];
- byte1 = new char[0];
- int n1 = 0;
- String s = "0000";
- BufferedReader in = new BufferedReader(
- new InputStreamReader(System.in));
- try
- {
- System.out.println("Enter:");
- s = in.readLine();
- n1 = s.length();
- byte1 = new char[n1];
- s.getChars(0, n1, byte1, 0); // 將讀入的 n1 個字元,放進 byte1 字元陣列。
- }
- catch (Exception e)
- {
- System.out.println("Error:" + e.toString());
- }
-
- Permutation perm1 = new Permutation(); // 建立排列計算物件
- perm1.N = n1; // 設定字元數
- perm1.perm(byte1, 0, ""); // 第一個參數為輸入字串,第二個參數 0 為陣列第一個位置
- }
-
- }
-
- class Permutation
- {
- public int N;
- void perm(char[] num, int index, String str)
- {
- if (index >= num.length)
- System.out.println(str);
- else
- {
- for (int i = 0; i < num.length; i++)
- if (str.indexOf(num[i]) == -1)
- perm(num, index + 1, str + " " + num[i]);
- }
- }
- }
-
留言
張貼留言