-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_Keypad_configuration.java
38 lines (33 loc) · 1.06 KB
/
print_Keypad_configuration.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
package Hard;
import java.util.HashMap;
import java.util.Scanner;
public class print_Keypad_configuration {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<Integer, String> hashMap = new HashMap<>();
hashMap.put(1, "abc");
hashMap.put(2, "def");
hashMap.put(3, "ghi");
hashMap.put(4, "jkl");
hashMap.put(5, "mnop");
hashMap.put(6, "qrst");
hashMap.put(0, "?!");
hashMap.put(7, "uv");
hashMap.put(8, "wxyz");
hashMap.put(9, ".;");//jkl wxyz qrst
printKeypad_configuration(n, hashMap, "");
}
private static void printKeypad_configuration(int n, HashMap<Integer, String> hashMap, String res) {
if(n == 0){
System.out.println(res);
return;
}
int rem = n%10;
String str = hashMap.get(rem);
n = n/10;
for (int i = 0; i < str.length(); i++) {
printKeypad_configuration(n, hashMap, res+str.charAt(i));
}
}
}