-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintEncoding.java
More file actions
47 lines (37 loc) · 1.34 KB
/
Copy pathPrintEncoding.java
File metadata and controls
47 lines (37 loc) · 1.34 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
public class PrintEncoding {
public static void main(String[] args) {
printEncoding("655196", "");
}
private static void printEncoding(String str, String asf) {
if (str.length() == 0) {
System.out.println(asf);
return;
} else if (str.length() == 1) {
String ch0 = str;
if (ch0.equals("0")) {
return;
}
int numForCh0 = Integer.parseInt(ch0);
String alphabetForCh0 = (char) ('a' + numForCh0 - 1) + "";
String roq0 = "";
printEncoding(roq0, asf + alphabetForCh0);
} else {
String ch0 = str.substring(0, 1);
if (ch0.equals("0")) {
return;
}
int numForCh0 = Integer.parseInt(ch0);
String alphabetForCh0 = (char) ('a' + numForCh0 - 1) + "";
String roq0 = str.substring(1);
printEncoding(roq0, asf + alphabetForCh0);
// 2 numbers ka khel
String ch01 = str.substring(0, 2);
int numForCh01 = Integer.parseInt(ch01);
if (numForCh01 <= 26) {
String alphabetForCh01 = (char) ('a' + numForCh01 - 1) + "";
String roq01 = str.substring(2);
printEncoding(roq01, asf + alphabetForCh01);
}
}
}
}