Java code for permutations