Assignment # 74 and Safe Square Root

Code

    /// Name: Tommy Oyuntseren
    /// Period: 7
    /// Program Name: SafeSquareRoot
    /// File Name: SafeSquareRoot.java
    /// Date: 1/26/2016

import java.util.Scanner;

public class SafeSquareRoot
{
    public static void main(String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        
        int number;
        
        System.out.println("SQUARE ROOT!");

            System.out.print("Enter a number: ");
            number=keyboard.nextInt();
            
            while (number < 0)
            {
                System.out.println("You can't take the square root of a negative number, silly.");
                System.out.print("Try again: ");
                number=keyboard.nextInt();
            }
        
            System.out.println("The square root of " + number + " is " + (Math.sqrt(number)) + ".");
    }
}
    
   

  

Picture of the output

Assignment 74