Answer:
The Java code is given below with appropriate comments
Explanation:
import java.util.*;
class Main {
static Set<String> set = new HashSet();
static void printPerms(char ch[], int ind){
//If end of string is reached, add it to set
if(ind==ch.length){
set.add(new String(ch));
return;
}
for(int i=ind;i<ch.length;i++){
//Only swap if lower case
if((ch[i]>='a' && ch[i]<='z')&&((ch[ind]>='a' && ch[ind]<='z'))){
char t = ch[i];
ch[i] = ch[ind];
ch[ind] = t;
}
printPerms(ch,ind+1);
if((ch[i]>='a' && ch[i]<='z')&&((ch[ind]>='a' && ch[ind]<='z'))){
char t = ch[i];
ch[i] = ch[ind];
ch[ind] = t;
}
}
}
public static void main(String[] args) {
printPerms("aBbCc".toCharArray(),0);
System.out.println(set);
}
}