-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathst.java
More file actions
30 lines (29 loc) · 667 Bytes
/
st.java
File metadata and controls
30 lines (29 loc) · 667 Bytes
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
class st{
public static void main(String[] args) {
String s="aaabccdeeeff";
int c=1;
String arr[]=s.split("");
String r="";
for(int i=0;i<arr.length-1;i++){
if(arr[i].equals(arr[i+1])){
c++;
}
else{
if(c==1){
r=r+arr[i];
}
else{
r=r+arr[i]+c;
}
c=1;
}
}
if(c==1){
r=r+arr[arr.length-1];
}
else{
r=r+arr[arr.length-1]+c;
}
System.out.println(r);
}
}