import java.util.Scanner; class test { // the size of the array to check for sortedness public static final int SIZE = 5; // this function takes an array and returns whether or not the array is sorted public static boolean isSorted(int array[]) { // keep track of whether the array is sorted or not boolean sorted = false; // loop through the array for (int i = 0; i < array.length; i++) { // if the previous one is more than the current one, it's NOT in order! if (array[i - 1] > array[i]) { sorted = false; } else { // it must be in order! sorted = true; } } return sorted; } // this main function tests out the function above by asking the user to // enter some numbers and calling the function to see if they're sorted public static void main(String args[]) { // fill an array int[] array = new int[SIZE]; System.out.printf("Enter %d items: ", SIZE); Scanner in = new Scanner(System.in); for (int i = 0; i < SIZE; i++) { array[i] = in.nextInt( ); } // check if it's sorted if (isSorted(array)) { System.out.println("You entered items in order!"); } else { System.out.println("You did NOT enter items in order!"); } } }