Assignemnt #74 and Safe Square Root
Code
/// Name: Kyle Ivy
/// Period: 5
/// Program Name: SafeSquareRoot
/// File Name: SafeSquareRoot.java
/// Date Finished: 1/5/2016
import java.util.Scanner;
public class SafeSquareRoot {
public static void main( String[] args) {
Scanner keyboard = new Scanner(System.in);
double a, b;
System.out.println( "Square Root! ");
System.out.print( "Enter a number: " );
do {
a = keyboard.nextDouble();
if ( a >= 0 ){
b = Math.sqrt(a);
System.out.println( b );
}
else if ( a < 0 ){
System.out.println(" You can't take the square root of a negative number" );
System.out.print( "Try again: " );
}
} while ( a < 0 );
}
}
prog74.PNG