Common Permutation Problem In Java