-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmartKeypadAdv.java
More file actions
48 lines (42 loc) · 1.4 KB
/
smartKeypadAdv.java
File metadata and controls
48 lines (42 loc) · 1.4 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
package recursionCB;
import java.util.ArrayList;
import java.util.Scanner;
public class smartKeypadAdv {
public static Scanner scn=new Scanner(System.in);
public static ArrayList <String> smart(String str1,String str2,int ind1,int ind2)throws Exception{
if(str1.length()==ind1) {
ArrayList <String> baseResult=new ArrayList<>();
return baseResult;
}
ArrayList <String> recResult;
if(ind2==str2.length()-1) {
recResult=smart(str1,str2,ind1+1,0);
}
else {
recResult= smart(str1,str2,ind1,ind2+1);
}
ArrayList<String> myResult=new ArrayList <>();
myResult.add(""+str1.charAt(ind1)+str2.charAt(ind2));
for(int i=0;i<recResult.size();i++) {
myResult.add(recResult.get(i));
}
return myResult;
}
public static void main(String args[])throws Exception {
String Table[]= {" ",".+@$","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
String num=scn.next();
int firs=Integer.parseInt(num.substring(0,1));
int sec=Integer.parseInt(num.substring(1,2));
String arr[]= {"prateek", "sneha", "deepak", "arnav", "shikha", "palak",
"utkarsh", "divyam", "vidhi", "sparsh", "akku" };
ArrayList<String> res=smart(Table[firs],Table[sec],0,0);
for(int i=0;i<arr.length;i++) {
for(int j=0;j<res.size();j++) {
String str=res.get(j);
if(arr[i].contains(str)) {
System.out.println(arr[i]);
}
}
}
}
}