-
Notifications
You must be signed in to change notification settings - Fork 0
/
YT17.java
55 lines (43 loc) · 1.19 KB
/
YT17.java
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
50
51
52
53
54
55
import java.io.*;
class Y17
{
public static void main(String[] args)throws IOException
{
int n;
String temp="";
InputStreamReader I = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(I);
System.out.println("Enter the size of the array: ");
n=Integer.parseInt(br.readLine());
String a[]=new String[n];
System.out.println("Enter the N names: ");
for(int i=0; i<n; i++)
{
a[i]=br.readLine();
}
System.out.println("Original Array");
for(int i=0; i<n; i++)
{
System.out.print(a[i]+ " ");
}
//sorting process
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(a[i].compareTo(a[j])<0)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println();
System.out.println("Sorted Array");
for(int i=0; i<n; i++)
{
System.out.print(a[i]+ " ");
}
}
}