Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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
s[]
for(k=j; s[k]!='\0' ;k++) { s[k]=s[k+1]; }
s[k]!='\0'
s[k+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.
k+1
k
s.length - 2
for(k=j; k < s.length - 1 ;k++) { s[k]=s[k+1]; }
Add a comment
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
s[]array?s[k]!='\0'ands[k+1]will eventually throw your exception