Unfortunately Array's aren't my strong point and this final lab is giving me a bit of trouble. Basically I need to make it so the code will return true if the given array is sorted in ascending order (lowest to highest). or it will return false. Then i need to use from the main method to create and show two arrays and indicate whether or not they are sorted. I believe both my functions are correct however there's some logical issues going on I believe, I'm kinda stuck at this point, any help making since of this mess would be appreciated.
public static Random random = new Random(100);
public static void main(String[] args) {
int[] array1 = {5, 3, 6, 7, 0, 2, 4, 15, 1, 3};
int[] array2 = {0, 1, 2, 3, 4, 6, 7, 15, 99, 100, 100};
int[] array = createRandomArray(1000);
System.out.println("Sorted: " + isSorted(array1)); // false
System.out.println("Sorted: " + isSorted(array2)); // true
System.out.println("DONE!");
}
// TODO: Return true if array is sorted, fals othrwise.
// NOTE: should *NOT* use any of the methods of the "Arrays" Utility class!!!
private static int[] createRandomArray(int length) {
int[] result = new int[length];
for(int i = 0; i < length; i++) {
result[i] = random.nextInt();
}
return result;
}
static boolean isSorted(int[] theArray) {
for(int i = 1; i < array.length; i++) {
if(array[i] < array[i-1]) {
return false;
}
}
return true;
}
boolean bArraySorted = true; // true until demonstrated false...
}