How to Sort Three Variables in Ascending Order.

      No Comments on How to Sort Three Variables in Ascending Order.

Sorting three variables in ascending order.

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
int a = 99, b = 5, c = 68;
int small = 0, medium = 0, big = 0;
     if (a < b && a < c) {
	small = a;
	if (b < c) {
	   medium = b;
	   big = c;
	} else {
	  medium = c;
	  big = b;
	}
    } else if (b < a && b < c) {
	small = b;
	if (a < c) {
	  medium = a;
	  big = c;
	} else {
	  medium = c;
	  big = a;
	}
   } else {
	small = c;
	if (a < b) {
	medium = a;
	big = b;
	} else {
	medium = b;
	big = a;
  }
}
System.out.println("small: " + small + " medium: " + medium + " big: "+ big);
Share This!

Leave a Reply

Your email address will not be published.