Assignemnt #74 and Safe Square Root
Code
/// Name: Marco Correa
/// Period: 5
/// Program Name: Safe Square Root
/// File Name: Safe Square Root.java
/// Date Finished: 1/16/2016
import java.util.Scanner;
public class SafeSquareRoot
{
public static void main ( String[] args )
{
Scanner k = new Scanner(System.in);
System.out.print( "SQUARE ROOT!\nEnter a number: " );
int n = k.nextInt();
while ( n < 0 )
{
System.out.println( "The square root of a negative number is imaginary." );
System.out.print( "Do another: " );
n = k.nextInt();
}
double r = Math.sqrt(n);
System.out.println( "The square root of " + n + " is " + r );
}
}
Picture of the output