-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintencoding.java
More file actions
54 lines (45 loc) · 1.18 KB
/
Copy pathprintencoding.java
File metadata and controls
54 lines (45 loc) · 1.18 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
import java.util.*;
public class printencoding{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
printEncoding(str, "");
}
public static void printEncoding(String ques,String asf){
if(ques.length()==0){
System.out.println(asf);
return;
}
else if(ques.length()==1){
char ch= ques.charAt(0);
if(ch=='0'){
return;
}
else{
int chv= ch-'0';
char code =(char)('a'+chv-1);
asf =asf+code;
System.out.println(asf);
}
}
else{
char ch= ques.charAt(0);
String roq= ques.substring(1);
if(ch=='0'){
return;
}
else{
int chv= ch-'0';
char code= (char)('a'+chv-1);
printEncoding(roq, asf+code);
}
String ch12=ques.substring(0,2);
String roq12=ques.substring(2);
int ch12v=Integer.parseInt(ch12);
if(ch12v<=26){
char code=(char)('a'+ch12v-1);
printEncoding(roq12, asf+code);
}
}
}
}