-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAscendingOrDescendingOrderVersionTwo.java
More file actions
77 lines (75 loc) · 2.1 KB
/
AscendingOrDescendingOrderVersionTwo.java
File metadata and controls
77 lines (75 loc) · 2.1 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.util.*;
class AscendingOrDescendingOrderVersionTwo{
static int a, b, check, x=1, z=9, temp;
static String asdDsd;
int[] num=new int [10];
Scanner sc=new Scanner (System.in);
void getData(){
for(b=0; b<=9; b++){
System.out.println("Enter the"+" "+x+" "+"number:\t");
num[b]=sc.nextInt();
x++;
}
System.out.println("Please enter \"A\" for ascending order and \"D\" for descending order:\t");
asdDsd=sc.next();
System.out.println(asdDsd);
if ((asdDsd.equals("d"))|(asdDsd.equals("?d")))
descendingOrder();
else if ((asdDsd.equals("d"))|(asdDsd.equals("d")))
ascendingOrder();
else if(check==0)
System.out.println("Invalid input. Please try again later");
}
void ascendingOrder(){
x=1;
b=0;
a=0;
for (b=0; b<=10; b++){
for (a=0; a<=z; a++){
if (num[b]<num[x]){
temp=num[x];
num[x]=num[b];
num[b]=temp;
z--;
x++;
check=20;
}
}
}
putData();
}
void descendingOrder(){
x=1;
b=0;
a=0;
for (b=0; b<=10; b++){
for (a=0; a<=z; a++){
if (num[b]<num[x]){
temp=num[x];
num[x]=num[b];
num[b]=temp;
z--;
x++;
check=20;
System.out.println(num[0]+"\t"+num[1]+"\t"+num[2]+"\t"+num[3]+"\t"+num[4]+"\t"+num[5]+"\t"+num[6]+"\t"+num[7]+"\t"+num[8]+"\t"+num[9]);
}
}
}
putData();
}
void putData(){
if (check==10){
System.out.println("The following are arranged in ascending order");
System.out.println(num[0]+"\t"+num[1]+"\t"+num[2]+"\t"+num[3]+"\t"+num[4]+"\t"+num[5]+"\t"+num[6]+"\t"+num[7]+"\t"+num[8]+"\t"+num[9]);
}
if (check==20){
System.out.println("The following are arranged in descending order");
System.out.println(num[0]+"\t"+num[1]+"\t"+num[2]+"\t"+num[3]+"\t"+num[4]+"\t"+num[5]+"\t"+num[6]+"\t"+num[7]+"\t"+num[8]+"\t"+num[9]);
}
}
public static void main(String[] args){
AscendingOrDescendingOrderVersionTwo aodovt= new AscendingOrDescendingOrderVersionTwo();
System.out.println("This application arranges the given number in descending or ascending order\n\n");
aodovt.getData();
}
}