Smart keypad 1 test cases not pass

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
String s = scn.next();
int n = Integer.parseInt(s);
String[] table = { " ", “.+@$”, “abc”, “def”, “ghi”, “jkl”, “mno”, “pqrs”, “tuv”, “wxyz” };
int a = n / 10, b = n % 10;
codes(table[a], table[b], table[b]);
}

public static void codes(String a, String b, String c) {
	if (a.length() == 0) {
		return;
	}
	if (b.length() == 0) {
		codes(a.substring(1), c, c);
	} else {
		System.out.print(a.charAt(0));
		System.out.println(b.charAt(0));
		codes(a, b.substring(1), c);
	}
}

} I don’t know Why please correct the problem

your code only works if input string has a length of 2.

Suggested approach:
Your are given this string input table:
string table[] = { " ", “.+@$”, “abc”, “def”, “ghi”, “jkl” , “mno”, “pqrs” , “tuv”, “wxyz” };

Here if you press 0 it will give you " ", if you press 1 it will give “.+@$” and so on.

In the output you have to print all possible string combinations for a input string string say 12.
If you press 1, possible characters are: .+@$
If you press 2, possible characters are: abc
Hence output will be combination of all the characters.

Use recursion.

  • Bigger Problem : To Print the codes for given whole length String.
  • Smaller Problem : Assume the recursion works and will give you ans for String of length n - 1 .
    Self Work : In order to make you smaller prblm your problem all you need to work for the first character and add one by one your all possible codes in the ans and the work will be done.