Assignment = Safe Square Root
Code
/// Name: Sam Wilson
/// Period: 6
/// Program Name: Safe Square Root
/// File Name: squareroot.java
/// Date Finished: 2/02/16
import java.util.Scanner;
public class squareroot
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int inp;
System.out.println("Enter a Number To find the Squareroot of the number");
while (!keyboard.hasNextInt())
{
keyboard.next();
System.out.println("Please enter a valid Input");
System.out.println();
}
inp = keyboard.nextInt();
while (inp <= 1)
{
System.out.println("Please enter a valid Input");
inp = keyboard.nextInt();
}
double answ = Math.sqrt(inp);
System.out.println();
System.out.println(answ);
System.out.println("Square root of " +inp+" is "+answ);
}
}
Picture of the output