Recursion keypad code

public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
String table[]= {"",“abc”,“def”,“ghi”,“jkl”,“mno”,“pqrs”,“tuv”,“wx”,“yz”};
String n[]=new String[2];
for(int i=0;i<2;i++)
n[i]=scn.nextLine();
if((Integer.parseInt(n[0])==0)||(Integer.parseInt(n[0])>9)||(Integer.parseInt(n[1])>9))
System.out.close();
else System.out.println(KeypadCode(table,Integer.parseInt(n[0]),Integer.parseInt(n[1]),"",0,0,0));
}
public static int KeypadCode(String table[],int x,int y,String result,int count,int i,int j){
if(i==table[x].length())
{ System.out.print(result);
System.out.println();
return count;
}
if(j==table[y].length())
{
return KeypadCode(table,x,y,result,count,i+1,0);
}
return KeypadCode(table,x,y,result+table[x].charAt(i)+table[y].charAt(j)+" ",count+1,i,j+1);

}

run error
could not find error

how to get the integer from a string
for example a string is 12,so how we can get 1 and 2


check this code,this is updated code
cound not pass third test case


check this one

HI @monika

For input 1, output should be a b c 3.
Your code doesn’t work for that case.

1 Like

gotcha
thanks @Riyabansal98