-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoderByteStringChallenge(str).java
40 lines (36 loc) · 1.18 KB
/
CoderByteStringChallenge(str).java
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
import java.util.*;
public class Main {
public static void main(String[] args) {
String str = "aabbcde";
StringBuilder sb1 = new StringBuilder();
int count=1;
int i;
for(i=0; i<str.length()-1; i++){
if(str.charAt(i) != str.charAt(i+1) && count == 1){
sb1.append(count+""+str.charAt(i));
}
else if(str.charAt(i) == str.charAt(i+1)){
count++;
}
else if(str.charAt(i) != str.charAt(i+1) && count >= 2){
sb1.append(count+""+str.charAt(i));
count=1;
}
}
sb1.append(count+""+str.charAt(i));
String ChallengeToken = "i8a0qgr2bd";
String[] strArr = ChallengeToken.split("");
HashSet<String> hs= new HashSet<>(Arrays.asList(strArr));
StringBuilder sb = new StringBuilder();
for( i=0; i<sb1.length(); i++){
String s1 = ""+sb1.charAt(i);
if(hs.contains(s1)){
sb.append("--"+s1+"--");
}
else{
sb.append(s1);
}
}
System.out.println(sb.toString());
}
}