Sort3.java


This is the syntax highlighted version of Sort3.java from 2.3 Conditionals, Loops of
Introduction to Computer Science by Robert Sedgewick and Kevin Wayne.


/*************************************************************************
 *  Compilation:  javac Sort3.java
 *  Execution:    java Sort A B C
 *  
 *  Reads in three integers and prints them out in sorted order without
 *  using a loop.
 *
 *  % java Sort3 33 22 18
 *  18 22 33
 *
 *  % java Sort3 43 12 8
 *  8 12 43
 *
 *************************************************************************/

public class Sort3 { 
    public static void main(String[] args) { 
        int A = Integer.parseInt(args[0]);
        int B = Integer.parseInt(args[1]);
        int C = Integer.parseInt(args[2]);

        if (B < A) { int t = B; B = A; A = t; }
        if (C < B) { int t = C; C = B; B = t; }
        if (B < A) { int t = B; B = A; A = t; }

        System.out.println(A + " " + B + " " + C);
    }

}


Last updated: Mon Sep 13 17:53:55 EDT 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.