-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.java
More file actions
43 lines (38 loc) · 1.24 KB
/
Copy pathsorting.java
File metadata and controls
43 lines (38 loc) · 1.24 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
import java.util.Scanner;
public class sorting {
public static void main(String[] args) {
// Gathering the three input values and storing them in the variables a, b and c
System.out.println("Please enter three numbers each followed by return.");
int a, b, c;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
System.out.println("");
// check if a<b<c
if (a <= b && b <= c) {
System.out.println(a + ", " + b + ", " + c);
}
// check if a<c<b
else if (a <= b && a <= c && b >= c) {
System.out.println(a + ", " + c + ", " + b);
}
// check if b<c<a
else if (b <= c && c <= a) {
System.out.println(b + ", " + c + ", " + a);
}
// check if b<a<c
else if (b <= c && b <= a && c >= a) {
System.out.println(b + ", " + a + ", " + c);
}
// check if c<a<b
else if (c <= a && a <= b) {
System.out.println(c + ", " + a + ", " + b);
}
// check if last possible solution, c<b<a
else {
System.out.println(c + ", " + b + ", " + a);
}
sc.close();
}
}