Here is my code:

import java.util.*;

public class Problem6_19 {

public static void main(String[] args) {

Scanner input = new Scanner(;
// prompt the user for the length of the list
System.out.println("Enter a number for the length of the list: ");
int listLength = input.nextInt();
// list array and input
int[] number = new int[listLength];
for (int i = 0; i < number.length; i++) {
System.out.println("Enter a value: ");
number[i] = input.nextInt();
// show the output
if (isSorted(number)) {
System.out.println("The list is sorted");

} else
System.out.println("The list is NOT sorted");


public static boolean isSorted(int[] list) {
// sort list from min to max
for (int i = 0; i < list.length; i++) {
if (list[i] > list[i + 1])

return false;
i++;// plus i/isSorted = true will be out of bounds

return true;


For some reason if I input a list that is only 3 numbers long, the program will not run and has an error. However, if I input a longer list the program works.