-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram69.java
More file actions
25 lines (19 loc) · 788 Bytes
/
Program69.java
File metadata and controls
25 lines (19 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class Program69 {
//Print keypad Combination
public static String[] keypad = {".", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tu", "vwx", "yz"};
public static void printComb(String str, int idx, String combination) {
if (idx == str.length()) {
System.out.println(combination);
return;
}
char currChar = str.charAt(idx);
String mapping = keypad[currChar - '0']; // mapping of currChar to keypad string
for (int i = 0; i < mapping.length(); i++) {
printComb(str, idx + 1, combination + mapping.charAt(i));//adding levels to the combination
}
}
public static void main(String[] args) {
String str = "23";
printComb(str, 0, "");
}
}