-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayCheckSorted.java
More file actions
46 lines (42 loc) · 1.31 KB
/
ArrayCheckSorted.java
File metadata and controls
46 lines (42 loc) · 1.31 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
import java.util.Scanner;
public class ArrayCheckSorted {
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter a size of array :- ");
int n=obj.nextInt();
int array[]=new int[n];
System.out.println("Enter a array element :- ");
for(int i=0;i<n;i++){
array[i]=obj.nextInt();
}
sort(array, n);
obj.close();
}
public static void sort(int array[],int n){
int i=0;
if(array[i]<array[i+1]){
for(i=1;i<n;i++){
if(array[i-1]<=array[i]){
continue;
}
else{
System.out.println("Array is not sorting !");
return;
}
}
System.out.println("YES! Array is sorting in Ascending order");
}
else{
for(i=1;i<n;i++){
if(array[i-1]>=array[i]){
continue;
}
else{
System.out.println("Array is not sorting !");
return;
}
}
System.out.println("YES! Array is sorting in Descending order");
}
}
}