-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.java
More file actions
53 lines (50 loc) · 1.45 KB
/
array.java
File metadata and controls
53 lines (50 loc) · 1.45 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
import java.io.*;
class array
{
static int i,n,j,ch;
public static void main(String args[])throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("<<< ENTER NUMBER OF NUMBERS TO BE ARRANGED");
n=Integer.parseInt(buf.readLine());
int a[]=new int[n];
System.out.println("<<< ENTER"+n+" NUMBERS.... >>>");
for(i=0;i<n;i++)
{
a[i]=Integer.parseInt(buf.readLine());
}
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
System.out.println("1:ASCENDING ORDER ");
System.out.println("2:DESCENDING ORDER ");
System.out.println("ENTER A CHOICE");
ch=Integer.parseInt(buf.readLine());
if(ch==1)
{
System.out.println("NUMBERS ARRANGED IN ASCENDING ORDER IS");
for(i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
else
if(ch==2)
{
System.out.println("NUMBERS ARRANGED IN DESCENDING ORDER IS");
for(i=n-1;i>=0;i--)
{
System.out.println(a[i]);
}
}
else
System.out.println("INVALID CHOICE !!!!!!!!!!!!!!");
}
}