class Conditional { public static void printInOrder(double x, double y) { if(x < y) { System.out.println(x + "," + y); } else { System.out.println(y + "," + x); } } public static void printInOrder(double x, double y, double z) { if(x < y) { if(x < z) { System.out.print(x+","); printInOrder(y, z); // End if(x < z) } else { System.out.print(z+","); printInOrder(x, y); } // End else of if(x < z) } else { if(y < z) { System.out.print(y); printInOrder(z, x); } else { System.out.print(z); printInOrder(x, y); } } } public static boolean is_int(double x) { return ((int)(x) == x); } public static boolean isSquare(int x) { return is_int(Math.sqrt(x)); } public static void printWithSwap(double x, double y, double z) { if(x > y) { double temp = x; x = y; y = temp; } // At this point, x is the min of x and y if(x > z) { double temp = z; x = z; z = temp; } // At this point, x is the min of x, y, and z if(y > z) { double temp = y; y = z; z = temp; } // At this point x <= y <= z System.out.println(x + "," + y + "," + z); } // End printWithSwap() public static String convert(String date) { int dash1 = date.indexOf("-"); //int dash2 = date.indexOf("-", dash1+1); int dash2 = date.lastIndexOf("-"); int diff = dash2 - dash1; String monthStr = date.substring(dash1+1, dash2); if(monthStr.length() == 1) { monthStr = "0"+monthStr; } String dateStr = date.substring(0, dash1); if(dateStr.length() == 1) { dateStr = "0" + dateStr; } // old code now String all_months = "01Jan02Feb03Mar04Apr05May06Jun07Jul08Aug09Sep10Oct11Nov12Dec"; int month_index = all_months.indexOf(monthStr); String month3Letters = all_months.substring(month_index+2, month_index+2+3); String yearStr = date.substring(dash2+1); return dateStr + " " + month3Letters + ", " + yearStr; } // End convert() public static void main(String[] args) { double x = 8; double y = 9; double z = -1; printInOrder(x, y, z); System.out.println("isSquare(25) is " + isSquare(25)); System.out.println(convert("19-01-2005")); System.out.println(convert("19-1-2005")); } }