String compression

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
int n=s.length();
boolean visit[]=new boolean[n];
for(int i=0;i<n;i++){
visit[i]=true;
}
ArrayList list=new ArrayList();
for(int i=0;i<s.length();i++){
int count=0;
if(visit[i]==true){
char x=s.charAt(i);
for(int j=0;j<n;j++)
{
if(s.charAt(j)==x){
visit[j]=false;
count++;
}
}
char r=(char)count;
list.add(x);
if(count>1){
list.add®;
}
}
}
for(int i=0;i<list.size();i++){
System.out.print(list.get(i));
}
}
}
please provide the solution i am stucked up for solving this

@karthik1989photos bro here is your corrected code. but you should have checked previous thread and you will be able to understand the issue.
Carefully see the test case:-
aaabbccds
output :- a3b2c2d1s1
your :- a3b2c2ds

That what I was trying to tell you in last thread.
Now if your query is resolved, close all threads related to this question by marking them resolved and rate full!

import java.util.*;

public class Main {

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

String s=sc.nextLine();

int sum=1;

String out="";

for(int i=0;i<s.length()-1;i++)

{

if(s.charAt(i)==s.charAt(i+1))

{

sum++;

}

else

{

out=out+s.charAt(i) ;

out=out+sum;

sum=1;

}

}

out=out+s.charAt(s.length()-1);

out=out+sum;

System.out.println(out);

}

}

plz give me a reply i m not getting that logic …correct my code

@karthik1989photos bro this is your corrected code, have you even submitted it? check the above comment atleast! I have corrected the code and pasted above! This is your code which you submitted in previous thread not mine! Check your previous thread this is the code you submitted i just made corrections in it!