Assignment #74 and Safe Square Roots
Code
//Name: Mark Katz
///Period: 6
///Program Name: Safe Square Root
///File Name: squareroot.java
///Date Finished: 10/30/15
import java.util.Scanner;
public class squareroot
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
double root;
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( "Enter a number: ");
number = keyboard.nextInt();
}
root = Math.sqrt(number);
System.out.println( "The square root of " + number + " is " + root );
}
}
Picture of the output