public class Demo {
public static void permutations(String[] str,int s,int e){
if(s == e){
for (int i = 0; i < str.length; i++){
System.out.print(str[i] + " ");
}
System.out.println();
}else{
for(int i = s; i <= e;i++){
swap(str,s,i);
permutations(str,s + 1,e);
swap(str,s,i);
}
}
}
public static void swap(String[] str ,int m ,int n){
String temp = str[m];
str[m] = str[n];
str[n] = temp;
}
public static void main(String[] args) {
String[] str = {"a","b","c"};
permutations(str,0,str.length-1);
}
}
a b c
a c b
b a c
b c a
c b a
c a b