Assignemnt #74: Safe Square Root

Code

    /// Name: Cassie
    /// Period: 6
    /// Program Name: Safe Square Root
    /// File Name: root.java
    /// Date Finished: 1/28/2016
    
    import java.util.Scanner;
    
    class root
    {
        public static void main( String[] args )
        {
            Scanner keyboard = new Scanner(System.in);
            double number;
            
            System.out.println( "SQUARE ROOT!" );
            System.out.print( "Enter a number: " );
            number = keyboard.nextDouble();
            
            while  ( number < 1 )
            {
                System.out.println( "You can't take the square root of a negative number, silly." );
                System.out.print( "Try again: " );
                number = keyboard.nextDouble();
            }
                
            System.out.println( "The square root of " + number + " is " + Math.sqrt(number) + "." );
        }
    }
    

Picture of the output

Assignment 74