Why my code is note working

Why is is happening,why my code is note working

@ashishsoni1412 Remember when the no. of consecutive occurrences is 1 you don’t have to write 1 in front of that character. For example :
aaabbcd
answer should be : a3b2cd
but your code is giving : a3b2c1d1. To remove this Problem add an if else statement for count = 1;
Corrected Code is below :

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();
	   for(int i=0;i<S.length();i++){
		   int count=1;
		   while(i<n-1 && S.charAt(i)==S.charAt(i+1)){
			   count++;
			   i++;
		   }
		  // String A+=(S.charAt(i)+""+count);
		  if(count == 1)
		     System.out.print(S.charAt(i));
		  else
		     System.out.print(S.charAt(i)+""+count);
	   }

    }
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.