-
Notifications
You must be signed in to change notification settings - Fork 0
/
Print Keypad Combinations Code
53 lines (50 loc) · 1.42 KB
/
Print Keypad Combinations Code
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
public class solution {
public static void printKeypad(int input){
// Write your code here
printKeypad(input,"");
}
public static void printKeypad(int input,String output){
if(input==0){
System.out.println(output);
return;
}
int rem=input%10;
char helperArray[]=helper(rem);
printKeypad(input/10,helperArray[0]+output);
printKeypad(input/10,helperArray[1]+output);
printKeypad(input/10,helperArray[2]+output);
if(helperArray.length==4){
printKeypad(input/10,helperArray[3]+output);
}
}
public static char[] helper(int n){
if(n==2){
char [] str={'a','b','c'};
return str;
}else if(n==3){
char [] str={'d','e','f'};
return str;
}else if(n==4){
char [] str={'g','h','i'};
return str;
}else if(n==5){
char [] str={'j','k','l'};
return str;
}else if(n==6){
char [] str={'m','n','o'};
return str;
}else if(n==7){
char [] str={'p','q','r','s'};
return str;
}else if(n==8){
char [] str={'t','u','v'};
return str;
}else if(n==9){
char[] str={'w','x','y','z'};
return str;
}else{
char [] str={' '};
return str;
}
}
}