forked from 14visheshjain/DataStructure-Algorithm-in-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathKPC.java
More file actions
52 lines (45 loc) · 927 Bytes
/
KPC.java
File metadata and controls
52 lines (45 loc) · 927 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package lecture9;
import java.util.Scanner;
public class kpc {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
String s = a.next();
kpc(s, "");
}
public static void kpc(String s, String ans) {
if (s.length() == 0) {
System.out.println(ans);
return;
}
char ch = s.charAt(0);
String temp = getCode(ch);
String ros = s.substring(1);
for (int i = 0; i < temp.length(); i++) {
kpc(ros, ans + temp.charAt(i));
}
}
public static String getCode(char ch) {
if (ch == '1')
return "abc";
else if (ch == '2')
return "def";
else if (ch == '3')
return "ghi";
else if (ch == '4')
return "jk";
else if (ch == '5')
return "lmno";
else if (ch == '6')
return "pqr";
else if (ch == '7')
return "stu";
else if (ch == '8')
return "vwx";
else if (ch == '9')
return "yz";
else if (ch == '0')
return "@#";
else
return "";
}
}