// 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, int len, boolean[] used) {
        if(ix < len) {
            for(int i = 0; i < a.length; i++) {
                if(!used[i]) {
                    used[i] = true;
                    writePerm(a, prefix + a[i], ix + 1, len, used);
                    used[i] = false;
                }
            }
        } else {
            System.out.println(prefix);
        }
    }
    public static void writePerm(char[] a, int len) {
        writePerm(a, "", 0, len, new boolean[a.length]);
    }
    public static void main(String[] args) {
        writePerm(new char[] { '0', '2', '2', '5', '6', '8' }, 3);
    }
}
