G
George
The below is my code to print permuation of 123:
public class per {
public static void main(String[] args) {
permutation("123", "");
}
private static void permutation(String p1, String p2) {
if (p1.length() == 0)
System.out.println(p2);
else {
for (int i = 0; i < p1.length(); i++)
permutation(p1.substring(0,i) + p1.substring(i+1), p2 + p1.charAt(i));
}
}
}
The results is:
123
132
213
231
312
321
What I want to do is that when (p1.substring(0,i) + p1.substring(i+1)) is
"2", do next line.
For example, that condition comes true when doing the line of "132", the
remaining process to produce "132" skipped and to do next line "213".
Any idea would be appreciated.
public class per {
public static void main(String[] args) {
permutation("123", "");
}
private static void permutation(String p1, String p2) {
if (p1.length() == 0)
System.out.println(p2);
else {
for (int i = 0; i < p1.length(); i++)
permutation(p1.substring(0,i) + p1.substring(i+1), p2 + p1.charAt(i));
}
}
}
The results is:
123
132
213
231
312
321
What I want to do is that when (p1.substring(0,i) + p1.substring(i+1)) is
"2", do next line.
For example, that condition comes true when doing the line of "132", the
remaining process to produce "132" skipped and to do next line "213".
Any idea would be appreciated.