Code

Code

sort check (IsSorted function) for java


public class IsSorted {

	public static void main(String[] args) {
		System.out.println(isSorted(new int[] { 1, 2, 3, 4 })); // true
		System.out.println(isSorted(new int[] { 1, 2, 3, 0 })); // false
	}

	public static boolean isSorted(int[] items) {
		for (int i = 0; i < items.length - 1; ++i) {
			if (items[i] > items[i + 1]) {
				return false;
			}
		}
		return true;
	}
}