-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeNumbersSort.java
More file actions
40 lines (38 loc) · 1.1 KB
/
Copy pathThreeNumbersSort.java
File metadata and controls
40 lines (38 loc) · 1.1 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
import java.util.Scanner;
public class ThreeNumbersSort {
//METHOD TO PRINT ARRAY
static void displayArray(int a[]){
for(int i=0; i<a.length; i++){
System.out.print(a[i] + " ");
}
}
//METHOD TO SORT ARRAY
static void sortElements(int a[]){
for(int i=0; i<a.length; i++){
a[i]= a.length-1-i;
}
displayArray(a);
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
//ARRAY SIZE AND ELEMENTS INPUT
System.out.print("Enter size of array: ");
int size= sc.nextInt();
if(size==3){
int arr[]= new int[size];
System.out.print("Enter " + size + " numbers(0,1,2): ");
for(int i=0; i<size; i++){
arr[i]= sc.nextInt();
}
if(arr[0]==0 && arr[1]==1 && arr[2]==2){
sortElements(arr);
}
else{
System.out.println("Valid array is- 0,1,2 !");
}
}
else{
System.out.print("Valid size is 3!");
}
}
}