-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
91 lines (82 loc) · 2.63 KB
/
Copy pathtest.java
File metadata and controls
91 lines (82 loc) · 2.63 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package SortingNumbers;
import java.util.Scanner;
/**
* @author Fatih ARI - 18.08.2021
* A program has been designed that sorts the 3 different numbers received from the user,
* according to the user's request, from largest to smallest or from smallest to largest.
*
* It is expected to entered 1 for the smallest to the largest and 2 for the largest to the smallest.
*
*/
public class test {
static short a, b, c, key, max=0, min=10000, median;
static char maxLetter, minLetter, medianLetter;
public static void gettingInput()
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number \"a\": ");
a = input.nextShort();
System.out.print("Enter the number \"b\": ");
b = input.nextShort();
System.out.print("Enter the number \"c\": ");
c = input.nextShort();
System.out.print("\nEnter 1 for ascending order and 2 for descending order: ");
key = input.nextShort();
input.close();
}
public static void controlNumbers()
{
if(a > max){
max = a;
maxLetter = 'a';}
if(b > max){
max = b;
maxLetter = 'b';}
if(c > max){
max = c;
maxLetter = 'c';}
if(a < min){
min = a;
minLetter = 'a';}
if(b < min){
min = b;
minLetter = 'b';}
if(c < min){
min = c;
minLetter = 'c';}
if(max!=a && min!=a){
median = a;
medianLetter = 'a';}
else if(max!=b && min!=b){
median = b;
medianLetter = 'b';}
else if(max!=c && min!=c){
median = c;
medianLetter = 'c';}
}
public static void ascendingSort()
{
System.out.println("\n"+minLetter + " < " + medianLetter + " < " + maxLetter);
System.out.println(min + " < " + median + " < " + max + "\n");
}
public static void descendingSort()
{
System.out.println("\n"+maxLetter + " > " + medianLetter + " > " + minLetter );
System.out.println(max + " > " + median + " > " + min + "\n");
}
public static void main(String[] args)
{
gettingInput();
controlNumbers();
switch (key) {
case 1:
ascendingSort();
break;
case 2:
descendingSort();
break;
default:
System.out.println("You made the wrong choice.");
}
}
}