forked from Krushna-Prasad-Sahoo/JavaCode-Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintEncodings.java
More file actions
58 lines (44 loc) · 1.36 KB
/
PrintEncodings.java
File metadata and controls
58 lines (44 loc) · 1.36 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
49
50
51
52
53
54
55
56
57
58
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scn = new Scanner (System.in);
String s = scn.next();
printEncodings(s, "");
}
public static void printEncodings(String str, String ans) {
if(str.length()==0){
System.out.println(ans);
}
else if(str.length()==1){
char ch=str.charAt(0);
if(ch=='0'){
return;
}
else{
int chi= ch-'0';
char code = (char)('a'-1+chi);
System.out.println(ans+code);
}
}
else{
char ch=str.charAt(0);
String rest = str.substring(1);
if(ch=='0'){
return;
}
else{
int chi= ch-'0';
char code =( char)('a'-1+chi);
printEncodings(rest,ans+code);
}
String ch12 = str.substring(0,2);
String restall = str.substring(2);
int chv12 =Integer.parseInt(ch12);
if(chv12<=26){
char code = (char)('a'-1+chv12);
printEncodings(restall,ans+code);
}
}
}
}