-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecryptedString.java
More file actions
33 lines (32 loc) · 1.08 KB
/
DecryptedString.java
File metadata and controls
33 lines (32 loc) · 1.08 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
public class DecryptedString{
public static void main(String[] args) {
String str = "ab4c12ed3";
int k = 21;
System.out.println(findChar(str,k));
}
public static char findChar(String str, int k){
String finalString="",repString="";
String numString="";
for(int i=0;i<str.length();i++){
char c= str.charAt(i);
if(c<='z' && c>='a'){
finalString=finalString+c;
repString=repString+c;
}else if(c<='9' && c>='1'){
numString="";
while(i< str.length() && str.charAt(i)>='1' && str.charAt(i)<='9'){
numString=numString+str.charAt(i);
++i;
}
--i;
int multiplier = Integer.parseInt(numString);
for(int j=0;j<multiplier-1;j++){
finalString=finalString+repString;
}
repString="";
}
}
System.out.println(finalString);
return finalString.charAt(k-1);
}
}