The first part of the if ("incremental" check) is incorrect, it should be:
for (int i = 0; i < data.length-1; i++) { if (data[i] > data[i+1]) { return false; } } return true;
Conversely, a downward check should be (and note that this is enough to change the direction of the comparison operator):
for (int i = 0; i < data.length-1; i++) { if (data[i] < data[i+1]) { return false; } } return true;
In both cases, you must exit the loop as soon as you find one pair of numbers that do not contain the property of increasing or decreasing, and return true after the loop exits.
source share