(Java) Check array for increasing elements

前端 未结 5 1685
旧时难觅i
旧时难觅i 2021-01-03 13:48

I\'m attempting to create a method that checks an array for increasing elements. True should be returned if all the elements are in increasing order. I get an out-of-bounds

5条回答
  •  心在旅途
    2021-01-03 14:06

    You get that exception as when (i+1)'s value becomes array.length. For example if you have an array of length 10, the elements indexes will be from 0,1,2...till 9. so either you have to check till i < arr.length - 1 or you can modify your logic accordingly.

提交回复
热议问题