Assignment #74: Safe Square Root

Code

/// Name: Kiran O'Farrell
/// File Name: SafeSquareRoot.java
/// Program Name: Safe Square Root
/// Date Completed: 1/28/16

import java.util.Scanner;

public class SafeSquareRoot {
  
	public static void main (String[] args) {
		
		Scanner keyboard = new Scanner(System.in);
		
		double input;
		double output;
		
		System.out.println("Type in a number and I will output its square root.");
		input = keyboard.nextDouble();
		
		while (input >= 0) {
		
		output = Math.sqrt(input);
		System.out.println("The square root of " + input + " is " + output + " .");
		
		System.out.println("Type in a non-negative number and I will output its square root.");
		input = keyboard.nextDouble();
		
		}
		
		while (input < 0) {
		
		System.out.println("You can't take the square root of a negative number.");
		
		System.out.println("Type in a non-negative number and I will output its square root.");
		input = keyboard.nextDouble();
		
		}
		
		
	}
  
}
    

Picture of the output