-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray2.java
More file actions
56 lines (52 loc) · 1.5 KB
/
array2.java
File metadata and controls
56 lines (52 loc) · 1.5 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.*;
class array2
{
static int i,j,n,ch;
public static void main(String args[])throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("<<< ENTER NUMBER OF NAMES TO BE ARRANGED");
n=Integer.parseInt(buf.readLine());
String name[]=new String[n];
System.out.println("<<< ENTER NAMES OF "+n+" PERSONS");
for(i=0;i<n;i++)
{
name[i]=buf.readLine();
}
System.out.println("1:ASCENDING ORDER ");
System.out.println("2:DESCENDING ORDER ");
System.out.println("ENTER A CHOICE");
ch=Integer.parseInt(buf.readLine());
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(name[j].compareTo(name[j+1])>=0)
{
String s=name[j];
name[j]=name[j+1];
name[j+1]=s;
}
}
}
if(ch==1)
{
System.out.println("NAMES ARRANGED IN ASCENDING ORDER IS");
for(i=0;i<n;i++)
{
System.out.println(name[i]);
}
}
else
if(ch==2)
{
System.out.println("NAMES ARRANGED IN DESCENDING ORDER IS");
for(i=n-1;i>=0;i--)
{
System.out.println(name[i]);
}
}
else
System.out.println("INVALID CHOICE !!!!!!!!!!!!!!");
}
}