1

This is a loop inside other loops, s[] is a char array. By this I am moving char step by step.what should I do for correcting it

for(k=j; s[k]!='\0' ;k++)    
{                         
   s[k]=s[k+1];                          
}
3

1 Answer 1

1

You should realize that arrays in Java have a length, so your null terminated check is wrong. Since you access the k+1'th element inside the loop, k must not go beyond s.length - 2.

for(k=j; k < s.length - 1 ;k++)
{ 
    s[k]=s[k+1];   
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.