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 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) ;
if(sum>1){
out=out+sum;
}
sum=1;
}

}
out=out+s.charAt(s.length()-1);
if(sum>1){
out=out+sum;
}
System.out.println(out);
}
}
sir after so many times trying out for running testcases i got stuck up so plz provide me the solution

@karthik1989photos wait karthik lemme see the new issue!

@karthik1989photos see bro as pointed out earlier, there are two string compression questions, one is string compression another is strings-string compression your solution is perfectly fine for the second one even passing all the test cases.

You have even corrected the edge case which I told you to correct.
The difference is in 1st one you have to even mention the count for single letter but not in second problem. So check it!