Assignemnt #74 Safe Square Root

Code

   
    /// Name: Jake Johnson
    /// Period: 7
    /// Program Name: SafeSquareRoot
    /// File Name: SafeSquareRoot.java
    /// Date Finished: 1/28/2016
    
import java.util.Scanner;

public class SafeSquareRoot
{
public static void main( String[] args )
    {
        Scanner keyboard = new Scanner(System.in);
        int x;

        System.out.println( "SQUARE ROOT!" );
        System.out.print( "Enter a number: " );
        x = keyboard.nextInt();
    
        while ( x < 0)
        {

            System.out.println( "You can't take the square root of a negative number, silly." );
            System.out.print( "Try again: " );
            x = keyboard.nextInt();
        }


        System.out.println( "The square root of " + x + " is " + Math.sqrt(x) + "." );
    }
}

    

Picture of the output

This should work