001package algs21;
002import stdlib.*;
003/* ***********************************************************************
004 *  Compilation:  javac Sort3.java
005 *  Execution:    java Sort3 a b c
006 *
007 *  Reads in three integers and prints them out in sorted order without
008 *  using a loop.
009 *
010 *  % java Sort3 33 22 18
011 *  18 22 33
012 *
013 *  % java Sort3 43 12 8
014 *  8 12 43
015 *
016 *************************************************************************/
017
018public class XSort3 {
019        public static void main(String[] args) {
020                args = new String[] { "33", "22", "18" };
021
022                // read in 3 command-line integers to sort
023                int a = Integer.parseInt(args[0]);
024                int b = Integer.parseInt(args[1]);
025                int c = Integer.parseInt(args[2]);
026
027                // 3 compare-exchanges
028                if (b < a) { final int t = b; b = a; a = t; }
029                if (c < b) { final int t = c; c = b; b = t; }
030                if (b < a) { final int t = b; b = a; a = t; }
031
032                // print out results
033                StdOut.println(a + " " + b + " " + c);
034        }
035
036}