/***************************************************************
 * This code demonstrates an alternative to typing System.out
 * for output.  It also teaches more about the "buffer," and
 * how to force data stored in the buffer to output.
 * Functionally, it calculates the square root of the numbers
 * that are inputted.
 ***************************************************************
 *
 * Ryan Decker
 * Version 1
 *	January 22, 2007
 */
import java.io.PrintWriter; // needed for the PrintWriter object
import java.util.Scanner;

public class IO_deckerrw_Rooter
{
	 /*
	  * The main constructor; takes in arguments
	  * and uses them to implement the code.
	  */
    public static void main(String[] args)
    {
       double          value, result;       
       PrintWriter     screen;   // alternative to typing System.out
       Scanner         keyboard;
       
       screen   = new PrintWriter(System.out);       
       keyboard = new Scanner(System.in);

       screen.println("Enter a number: ");    
       screen.flush();  // forces the buffer to output to the screen
       
       while (keyboard.hasNext()) // can only exit the program by pressing Ctrl + Z
       {
          value = keyboard.nextDouble();
          result = Math.sqrt(value); // calculates the sqare root of value

          screen.printf("The square root of " + value + " is " + result);
          screen.flush();
          
          screen.println("\nEnter a number: ");       
        	 screen.flush();
       }

       screen.println("Done.\n");  // Notifies that the program has ended successfully     
       screen.flush();
    }
   
}
