PROGRAMMING AND CODE


Assignemnt #74

Code

/// Name: Justin Li
/// Period 7
/// Program Name: Safe Square Root
/// File Name: SafeSquareRoot.java
/// Date Finished: 1/7/16

import java.util.Scanner;

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

		double number, squareroot;
		
        squareroot = 0;
        System.out.print("Squre Root! \n Enter a number: ");
        number = keyboard.nextDouble();

		while (number != 0)
		{
            if (number >= 0)
            {
                squareroot = Math.sqrt(number);
                System.out.print("The square root of the number is: " + squareroot + "\nPlease enter another number: ");
                number = keyboard.nextDouble();
            }
            else if (number <= 0)
            {
                System.out.print("That is negative; please try again: ");
                number = keyboard.nextDouble();
            }
		} 
        
        
            System.out.print("Good Bye.");
            
       
        
	}
}


    

Picture of the output

Assignment 1