Ok, it's correct. :)
If you want you can test i < a1.length, which is conceptually the same just more concise (personally I prefer).
Type: Posts; User: andbin
Ok, it's correct. :)
If you want you can test i < a1.length, which is conceptually the same just more concise (personally I prefer).
Ok, please. You can post your, hope right, code. It could be useful to others and I can tell you if it's correct.
Think carefully about the following: the entire array is in ascending order only if all pairs are in ascending order. It's sufficient one (anywhere) pair not in ascending order to state immediately...
You are testing:
if (a1[i - 1] < a1[i]) {
return true;
}
This is right itself. But this means that only by the first occurrence of a1 [I]is-lower-than a1 it returns true, ignoring the...
First, the index variable i can reach the value of a1.length which is an index out of bounds. Thus, a1[i] will throw an exception when i equals a1.length.
Second (apart the first problem), your...