for loop - java.lang.ArrayIndexOutOfBoundsException looping? -


this loop inside other loops, s[] char array. moving char step step.what should correcting it

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

you should realize arrays in java have length, null terminated check wrong. since access k+1'th element inside loop, k must not go beyond s.length - 2.

for(k=j; k < s.length - 1 ;k++) {      s[k]=s[k+1];    } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -