Safe Square Root

Code

    /// Name: Rachel Smith
    /// Period: 5
    /// Program Name: Safe Square Root
    /// File Name: SafeSquareRoot.java
    /// Date Finished: 12/7/2015
    
    import java.util.Scanner;
    
    public class SafeSquareRoot {
        
        public static void main( String[] args ) {
            
            Scanner keyboard = new Scanner(System.in);
            
            int n;
            
            System.out.println( "SQUARE ROOT!" );
            
            System.out.print( "Enter a number: " );
            n = keyboard.nextInt();
            double sr = Math.sqrt(n); 
            
            while ( n <= 0 ) {
            System.out.println( "You can't take the square root of a negative number, silly." );
            System.out.print( "Try again: " );
            n = keyboard.nextInt();
            sr = Math.sqrt(n); 
            }
            
            System.out.println( "The square root of " + n + " is " + sr + "." );
            
        }
    }
    

Picture of the output

Assignment 1