Getting one error for a single testcase. Can anyone help, by pointing out what else i am missing?

import java.util.*;

class stringcompression{
public static void main(String [] args) {
Scanner sc = new Scanner (System.in);
String s;
s=sc.nextLine();
char [] c = s.toCharArray();
for(int i=0;i<c.length;i++) {
int counter =0;
for(int j=0;j<s.length();j++) {

			if(j<i && c[j]==c[i]) {
				break;
			}
			
			if(c[i]==c[j]) {
				counter++;
			}
			if(j==c.length-1) {
				if(counter>1) {
				System.out.print(c[i]+""+counter);
				}
				else {
					System.out.print(c[i]);
				}
			}
		}//end of i loop
	}
	
}

}

Hi Ashish

Let us suppose the string is aaabbbaa. In this, the output should is a3b3a2 instead of a5b3. You only have to count the contiguous occurances of the characters.

Hi @ashish_mohanty
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.