-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySortCheck.java
More file actions
33 lines (26 loc) · 838 Bytes
/
ArraySortCheck.java
File metadata and controls
33 lines (26 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class ArraySortCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] numbers = new int[10];
System.out.println("Enter list of 10 integers:");
for (int i = 0; i < 10; i++) {
numbers[i] = scanner.nextInt();
}
if (isSorted(numbers)) {
System.out.println("List is sorted!");
} else {
System.out.println("List is not sorted!");
}
scanner.close();
}
// Method to check if array of integers is sorted
public static boolean isSorted(int[] numbers) {
for (int i = 0; i < numbers.length - 1; i++) {
if (numbers[i] > numbers[i + 1]) {
return false;
}
}
return true;
}
}