// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Perm {
    public static void writePerm(char[] a, String prefix, int ix) {
        if(ix < a.length) {
            for(int i = 0; i < a.length; i++) {
                writePerm(a, prefix + a[i], ix + 1);
            }
        } else {
            System.out.println(prefix);
        }
    }
    public static void writePerm(char[] a) {
        writePerm(a, "", 0);
    }
    public static void main(String[] args) {
        char[] a = { 'a', 'b', 'c', 'd' };
        writePerm(a);
    }
}
