-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortedCheck.java
More file actions
49 lines (42 loc) · 1.23 KB
/
sortedCheck.java
File metadata and controls
49 lines (42 loc) · 1.23 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
package challanges;
public class sortedCheck {
public static void main(String[] args) {
System.out.println("Welcome to check your array sorted or Not");
int[] inputArray = arrayInputUtility.inputArray();
boolean isInc = IncreasingOrder(inputArray);
boolean isDec = DecreasingOrder(inputArray);
if(isDec || isInc){
System.out.println("Array Sorted");
}else{
System.out.println("Array Not Sorted");
}
}
public static boolean IncreasingOrder(int[] myArray){
if (myArray.length <= 1) {
return true;
}else{
int i = 1;
while (i < myArray.length) {
if (myArray[i] < myArray[i - 1]) {
return false;
}
i++;
}
}
return true;
}
public static boolean DecreasingOrder(int[] myArray){
if (myArray.length <= 1) {
return true;
}else{
int i = 1;
while (i > myArray.length) {
if (myArray[i] > myArray[i-1]) {
return false;
}
return false;
}
}
return true;
}
}