-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsSortedArray.java
More file actions
37 lines (34 loc) · 978 Bytes
/
Copy pathIsSortedArray.java
File metadata and controls
37 lines (34 loc) · 978 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
34
35
36
37
public class IsSortedArray {
public static void main(String[] args) {
System.out.println("welcome to array sorting check post\n");
int[] numArr = ArrayUtility.inputArray();
boolean isInc = isIncreasing(numArr);
boolean isDec = isDecreasing(numArr);
if (isInc || isDec) {
System.out.println("your array is sorted");
}
else {
System.out.println("your array is not sorted");
}
}
public static boolean isDecreasing(int[] numArr) {
int i = 1;
while (i<numArr.length) {
if (numArr[i] > numArr[i-1]) {
return false;
}
i++;
}
return true;
}
public static boolean isIncreasing(int[] numArr) {
int i = 1;
while(i < numArr.length) {
if(numArr[i] <numArr[i-1]) {
return false;
}
i++;
}
return true;
}
}