import java.util.*;
import java.io.*;

/** DemoLargestConsole - find the largest number in a series --
* console version.<p>
*
* This program is an example of a <i>console application</i> --
* a program that interacts with the user by reading characters
* from the keyboard and by writing characters to the system's display.
* <p>
*
* The purpose of this program and the next (<code>DemoLargestGUI</code>)
* is to contrast the behaviour of <i>console applications</i> with
* <i>GUI
* applications</i>.  At this point, we are not concerned with the
* inner workings of the programs.  We are concerned only with the
* behaviour of the programs from the perspective of the user.
* <p>
*
* The user is prompted to enter a series of numbers on the keybaord.
* Input
* continues until the program receives an end-of-file (EOF)
* condition, generated from the keyboard by entering CTRL-Z (Windows)
* or CTRL-D (unix).
* <p>
*
* Once input is terminated, the program determines the largest
* number in the series and outputs the result to the console.
* <p>
*
* To keep things reasonably simple, there is no
* input validation.  It is assumed that the user
* is "well behaved" and enters numbers only.<p>
*
* Screen snap...<br>
* <center><img src = "DemoLargestConsole-1.gif"></center><p>
*
* @see <a href="DemoLargestConsole.java">source code</a>
* @author Scott MacKenzie, 2003
*/
public class DemoLargestConsole
{
   public static void main(String[] args) throws IOException
   {
      // prepare to read from the keyboard

      BufferedReader stdin =
         new BufferedReader(new InputStreamReader(System.in));

      // get numbers from keyboard

      System.out.println("Enter numbers below");
      System.out.println("(terminate with CTRL-Z (Windows) or CTRL-D (unix))");
      String s = "";
      String line;
      while ((line = stdin.readLine()) != null)
         s = s + " " + line;

      // find the largest number

      double largest = findLargest(s);

      // output results

      System.out.println(); // dummy blank line needed (sometimes!)
      System.out.println("Largest = " + largest);         
   }
   
   public static double findLargest(String sArg)
   {
      StringTokenizer st = new StringTokenizer(sArg);

      double result = Double.MIN_VALUE;
      while (st.hasMoreTokens())
      {
         double value = Double.parseDouble(st.nextToken());
         if (value > result)
            result = value;
      }
      return result;
   }
}

