-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetkeypadcomb.java
More file actions
47 lines (29 loc) · 1.01 KB
/
Copy pathgetkeypadcomb.java
File metadata and controls
47 lines (29 loc) · 1.01 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
import java.util.*;
public class getkeypadcomb {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
String str= sc.next();
ArrayList<String> words= getKPC(str);
System.out.println(words);
}
public static String[] codes= {".;" ,"abc","def","ghi","jkl","mno","pqrs","tu","vwx","yz"};
public static ArrayList<String> getKPC(String str){
if(str.length()==0){
ArrayList<String> bres =new ArrayList<>();
bres.add("");
return bres;
}
char ch = str.charAt(0);
String ros= str.substring(1, ch);
ArrayList<String> rres= getKPC(ros);
ArrayList<String> mres= new ArrayList<>();
String codeforch= codes[ch];
for(int i =0 ; i<codeforch.length();i++){
char chcode=codeforch.charAt(i);
for(String rstr:rres){
mres.add(chcode+rstr);
}
}
return mres;
}
}