Assignemnt #74: Safe Square Root
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: SafeSquareRoot.java
/// File Name: SafeSquareRoot
/// Date Finished: 1/26/2016
import java.util.Scanner;
public class SafeSquareRoot
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
double number, solution;
System.out.println( " I will computate the square root of all positive integers " );
System.out.println( " Please input the number " );
System.out.print( "<" );
number = keyboard.nextDouble();
while ( number <= 0 )
{
System.out.println( "You cannot enter negetive numbers pleae input a positive one. " );
number = keyboard.nextDouble();
}
solution = Math.sqrt(number);
System.out.println( " The solution to the square root of " + number + " is" + solution + " . ");
}
}
Picture of the output