-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsortingInJava.java
More file actions
36 lines (36 loc) · 991 Bytes
/
sortingInJava.java
File metadata and controls
36 lines (36 loc) · 991 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
package dsa;
import java.util.Scanner;
public class sortingInJava
{
public static void main(String[] args)
{
int n, temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number of elements: ");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter the elements of the array: ");
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] < a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println("Array elements in descending order:");
for (int i = 0; i < n - 1; i++)
{
System.out.println(a[i]);
}
System.out.print(a[n - 1]);
}
}