-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrSort2.java
More file actions
39 lines (31 loc) · 1020 Bytes
/
ArrSort2.java
File metadata and controls
39 lines (31 loc) · 1020 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
38
39
import java.util.Scanner;
class ArrSort2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Size Of array :");
int size = sc.nextInt();
int arr[] = new int[size];
System.out.println("Enter array elements ");
for (int i = 0; i < size; i++) {
arr[i] = sc.nextInt();
}
System.out.println("Original Array is");
for (int j = 0; j < size; j++) {
System.out.print(arr[j] + " ");
}
// sorting logic
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
if (arr[i] < arr[j]) {
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
System.out.println("\nDescending Array Elements ");
for (int i = 0; i < size; i++) {
System.out.print(arr[i] + " ");
}
}
}