I need to create a program in java in which when the input given is say:
hhllyyjhhh
the output should be
h2l2y2j1h3
instead i get the output
h2l2y2j1
I know the reason why, but please tell me how should I correct it or may be tell a new logic.
in the following code T is the character array and ans is an empty string.
int counter=0;
for(int i=0;i<T.length;i++)
{
for(int j=i;j<T.length;j++)
{
if(T[i]==T[j])
{
counter++;
}
else
{
ans=ans+T[i]+counter;
i=j-1;
counter=0;
break;
}