/* * T01n05.java -- Find the smallest of three ints * * Java's Math class includes a method that would make this code shorter, * but it would also eliminate the opportunity to use both types of IF * statement in one short program! */ import java.util.*; public class T01n05 { public static void main (String [] args) { int item1, item2, item3, // the three contestants min; // will hold the smallest of the three Scanner keyboard = new Scanner (System.in); System.out.println("If you enter three integers, I will tell you " + "which is the smallest.\n\nEnter your three " + "integers; press Enter after each one.\n"); item1 = keyboard.nextInt(); item2 = keyboard.nextInt(); item3 = keyboard.nextInt(); // Find the smaller of the first two integers if (item1 < item2) min = item1; else min = item2; // If the third is even smaller, it's the smallest if (min > item3) min = item3; System.out.println("\nThe smallest of " + item1 + ", " + item2 + " and " + item3 + " is " + min + "."); } }