I am creating code to check if an array is in ascending order. I have created code that seems logical to me; however, when I input an array that is in ascending order, I receive an error message (but when I input an array that is not in ascending order, the code outputs "false, as it should). Here is my code:
public class Ordered {
public static boolean isSorted(int[] numbers) {
int length = numbers.length;
for (int i=0; i <= length-1; i++) {
if (numbers[i] > numbers[i+1]) { //here is where I think the error message is showing the issue is
return false;
}
}
return true;
}
}