001package algs21; 002import stdlib.*; 003/* *********************************************************************** 004 * Compilation: javac Sort5.java 005 * Execution: java Sort A B C D E 006 * 007 * Reads in five integers and prints them out in sorted order without 008 * using a loop. 009 * 010 * % java Sort5 33 22 18 66 43 011 * 18 22 33 43 66 012 * 013 * % java Sort5 43 22 18 22 33 014 * 18 22 22 33 43 015 * 016 * % java Sort5 43 12 8 4 1 017 * 1 4 8 12 43 018 * 019 *************************************************************************/ 020 021public class XSort5 { 022 public static void main(String[] args) { 023 args = new String[] { "33", "22", "18", "66", "43" }; 024 025 int a = Integer.parseInt(args[0]); 026 int b = Integer.parseInt(args[1]); 027 int c = Integer.parseInt(args[2]); 028 int d = Integer.parseInt(args[3]); 029 int e = Integer.parseInt(args[4]); 030 031 if (a > b) { final int t = a; a = b; b = t; } 032 if (d > e) { final int t = d; d = e; e = t; } 033 if (a > c) { final int t = a; a = c; c = t; } 034 if (b > c) { final int t = b; b = c; c = t; } 035 if (a > d) { final int t = a; a = d; d = t; } 036 if (c > d) { final int t = c; c = d; d = t; } 037 if (b > e) { final int t = b; b = e; e = t; } 038 if (b > c) { final int t = b; b = c; c = t; } 039 if (d > e) { final int t = d; d = e; e = t; } 040 041 StdOut.println(a + " " + b + " " + c + " " + d + " " + e); 042 } 043 044}