AP Computer Science --- Haas --- RecursivePermutations
/**
* This class generates permutations of a word.
*
* This class is complete and works as is.
*
* Your assignment is to trace through the program and
* hand in a "tree diagram" showing all of the calls to method perm.
*/
public class Permutations
{
public static void perm(String prefix, String s) {
int N = s.length();
if (N == 0) {
System.out.println(prefix);
}
else {
for (int i = 0; i < N; i++) {
perm(prefix + s.substring(i,i+1), s.substring(0, i) + s.substring(i+1, N));
}
}
}
public static void main(String[] args)
{
perm("","abc");
}
}