-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsArraySorted.java
More file actions
24 lines (22 loc) · 792 Bytes
/
IsArraySorted.java
File metadata and controls
24 lines (22 loc) · 792 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
public class IsArraySorted {
public static void main(String[] args) {
int[] marks = {10,20,30,40,50,60};
boolean isAscending = true;
boolean isDescending = true;
for (int i = 0; i < marks.length - 1; i++) {
if (marks[i] > marks[i + 1]) {
isAscending = false; // Not in ascending order
}
if (marks[i] < marks[i + 1]) {
isDescending = false; // Not in descending order
}
}
if (isAscending) {
System.out.println("Array is sorted in ascending order.");
} else if (isDescending) {
System.out.println("Array is sorted in descending order.");
} else {
System.out.println("Array is not sorted.");
}
}
}