public class keypad_ques {
public static ArrayList<String> GetCodes(String str,String[] table)
{
if(str.length()==0)
{
ArrayList<String> base=new ArrayList<>();
base.add("");
return base;
}
int i1=(int)str.charAt(0);
// String s1=table[i1];
String ros=str.substring(1);
ArrayList recres = GetCodes(ros, table);
String s1=table[i1];
ArrayList<String> myres=new ArrayList<>();
for(int i=0;i<recres.size();i++)
{
for(int j=0;j<s1.length();j++)
{
myres.add(recres.get(i)+s1.charAt(j));
}
}
return myres;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String table[] = { " ", ".+@$", "abc", "def", "ghi", "jkl" , "mno", "pqrs" , "tuv", "wxyz" };
System.out.println(GetCodes(str, table));
}
}
on netbeans, Iβm getting out of bound error and on coding blocks ide, run time error. I donβt see any problem while dry running. where is the mistake?