import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
String st = cin.next();
ArrayList al = new ArrayList<>();
printCombinations(st,"", al);
System.out.println(al);
}
public static void printCombinations(String str,String res,ArrayList ans){
if(str.length()==0){
ans.add(res);
return;
}
String table[]= { " ", “.+@$”, “abc”, “def”, “ghi”, “jkl” , “mno”, “pqrs” , “tuv”, “wxyz” };
String r = table[str.charAt(0)];
for(int i = 0;i< r.length(); i++){
printCombinations(str.substring(1),res+r.charAt(i),ans);
}
}
}======what’s the error in my code
Smart keypad 1 problem
your code is all correct. except line 16:
String r = table[str.charAt(0) - ‘0’]; //need to change character to index
Thanks.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.