class Permutation
{ static int maxIndex;
  static char[] feld;
  static String s;

  static void ausgabe(char[] a)
  {  for (int i=0; i<=maxIndex; i++) Out.print(a[i]);
     Out.print(" ");
  } //  ausgabe

  static void vertausche(char[] a, int i, int j)
  {  char ablage = a[i];
     a[i] = a[j];
     a[j] = ablage;
  } // vertausche

  static void perm(char[] a, int endIndex)
  {  if (endIndex==0)
            ausgabe(a);
     else { perm(a, endIndex-1);
            for (int i=0; i<=endIndex-1; i++)
            {  vertausche(a, i, endIndex);
               perm(a, endIndex-1);
               vertausche(a, i, endIndex);
            } // for i
          }
  } // perm

  public static void main(String args[]) // Hauptprogramm
  { Out.println("Ein String soll permutiert werden.");
    Out.print("Geben Sie den zu permutierenden String ein: ");
    s = In.readLine();
    maxIndex = s.length()-1;
    feld = s.toCharArray();
    perm(feld, maxIndex);
  } // Ende von main
} // Ende von class Permutation

