Hauke Ingmar Schmidt wrote:It is the -1 in Paul's answer. (Or you could iterate until j<arr.length; note the missing =).
Paul Clapham wrote:Unfortunately "doesn't seem to work" isn't a very helpful problem description. Could you tell us what's wrong? You can read our FAQ entry ItDoesntWorkIsUseless for more information about how to do that.
Campbell Ritchie wrote:There is also a conventional format for iterating it backwards
Tim Cooke wrote:Here's the problem. Here's a simplified version of what you have:
Firstly: Both for loops are iterating over the same array. The first loop starts at index 0 and stops at the last index, no problem here. The second loop however starts at 1 + the current index i, what happens when the first loop index is at the last index? The second loop starts and 1 + the last valid array index, which is invalid, and throws an IndexOutOfBoundsException.
Tim Cooke wrote:(Edit: Have a cow for successfully
making me look like a bit of a ninnycorrecting my mistake)
Yes. Sorry for the mistake.
Kat Rollo wrote: . . .
Hi, shouldn't it be i >= 0?