-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKeypad_Combinations.java
More file actions
33 lines (33 loc) · 931 Bytes
/
Keypad_Combinations.java
File metadata and controls
33 lines (33 loc) · 931 Bytes
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
package Programs2;
import java.util.*;
public class Keypad_Combinations {
public static void main(String[] args) {
int num;
Scanner s=new Scanner(System.in);
System.out.print("Enter an integer number : ");
num=s.nextInt();
String[] arr=keypad(num);
System.out.println("Keypad combinations which can be made of the integer number are : ");
for(int i=0;i<arr.length;i++)
System.out.println(arr[i]);
}
public static String[] keypad(int n){
if(n==0)
{
String[] arr={""};
return arr;
}
String[] str=keypad(n/10);
String word=num(n%10);
String []ans=new String[str.length*word.length()];
int k=0;
for(int j=0;j<word.length();j++)
for(int i=0;i<str.length;i++)
ans[k++]=str[i]+word.charAt(j);
return ans;
}
public static String num(int m){
String[] arr={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
return arr[m];
}
}