import java.io.*;
import java.util.Scanner;
/*******************************************************
 * The program demonstrates input and output by using
 * Scanner and PrintWriter class' methods.
 * 
 * @author Murat Akhmetov
 * @version V1 - 01/22/07
 * Lab4 / Section 0002
 *******************************************************/ 

public class IO_akhmetma_Rooter
{
    public static void main(String[] args)
    {
       double          value, // number entered by user
		                 result;// square root of value
       PrintWriter     screen;
       Scanner         keyboard;
       
       screen   = new PrintWriter(System.out);       
       keyboard = new Scanner(System.in);
		 
		 // 1st output prompts to enter a number by using PrintWriter screen
       screen.print("Enter a number: ");
		 screen.flush();  // prints out the string passed to print() method of
		                  // PrintWriter object screen
								
       // the loop executes inputing a number and outputing square root of
		 // the number as long as there is another token in Scanner keyboard
		 // by using hasNext() method of Scanner class
       while (keyboard.hasNext())
       {
          value = keyboard.nextDouble();// inputs a number by nextDouble()
			                               // method of Scanner class
          result = Math.sqrt(value);// calculates the number's square root

          // outputs value and result
          screen.printf("The square root of " + value + " is " + result + "\n");
          screen.flush();
          
			 // prompts to enter another number
          screen.print("Enter a number: ");       
        	 screen.flush();
	
       }

       // indicates the end of the program by outputing message
       screen.println("Done.\n");       
       screen.flush();
    }
    
}
