java – How to handle array:Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 3

 for(int i=0;i<length;i++)     

should be

 for(int i=0;i<length - 1;i++)

since you can have length - 1 number of comparisons.

Leave a Comment