-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA910.java.bak
More file actions
49 lines (42 loc) · 989 Bytes
/
A910.java.bak
File metadata and controls
49 lines (42 loc) · 989 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
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
class A910
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("----- Program will print ARRAY in DESCENDING Order -----");
System.out.println("Enter the size of array");
char a[] = new char[s.nextInt()];
for (int i=0;i<a.length ;i++ )
{
System.out.println("Enter the character for index "+i);
a[i] = s.next().charAt(0);
}
//Selection Sort method
// < is for sorting in decending
for (int i=0;i<a.length-1 ;i++ )
{
int min = a[i];
int min_index = i;
for (int j=i+1;j<a.length ;j++ )
{
if (a[j]>min)
{
min = a[j];
min_index = j;
}
}
if (i != min_index)
{
char temp = a[i];a
a[i] = a[min_index];
a[min_index]=temp;
}
}
System.out.println("Descending sorted array is :");
for (int i=0;i<a.length ;i++ )
{
System.out.print(" "+a[i]);
}
}
}