Assignemnt #74 and Safe Square Root
Code
/// Name: Raff Lisbona
/// Period: 6
/// Program Name: Safe Square Root
/// File Name: SafeSquareRoot.java
/// Date Finished: 12/14/2015
import java.util.Scanner;
public class SafeSquareRoots
{
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();
if ( n < 0 )
System.out.println("You can't take the square root of a negative number, silly.");
while ( n < 0 )
{
System.out.print("Enter a number: ");
n = keyboard.nextInt();
if ( n < 0 )
System.out.println("You can't take the square root of a negative number, silly head.");
}
System.out.println("The square root of " + n + " is " + Math.sqrt(n) + ".");
}
}
Picture of the output