-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneKeypad.java
More file actions
72 lines (53 loc) · 1.1 KB
/
PhoneKeypad.java
File metadata and controls
72 lines (53 loc) · 1.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public interface PhoneKeypad {
public static String words(int n){
String s="";
switch(n){
case 2:s="abc";
break;
case 3:s="def";
break;
case 4:s="ghi";
break;
case 5:s="jkl";
break;
case 6:s="mno";
break;
case 7:s="pqr";
break;
case 8:s="stuv";
break;
case 9:s="wxyz";
break;
}
return s;
}
public static String[] phoneKeypad(int m){
if(m/10==0){
String t=words(m);
String arr[]=new String[t.length()];
for(int i=0;i<t.length();i++){
arr[i]=String.valueOf(t.charAt(i));
}
return arr;
}
String[]smallOutput=phoneKeypad(m/10);
String[] output=new String[smallOutput.length*words(m%10).length()] ;
int t=0;
for(int k=0;k<words(m%10).length();k++)
{
for(int j=0;j<smallOutput.length;j++)
{
output[t]=smallOutput[j]+words(m%10).charAt(k);
t++;
}
}
return output;
}
public static void main(String[] args) {
int t=234;
String[] arr=phoneKeypad(t);
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
}