Assignment 74, Safe Square Root
Code
///Name: Stella Koliavas
///Period: 5
///File Name: BabyCalc.java
///Date Finshed: 1/14/16
import java.util.Scanner;
public class Root
{
public static void main(String[] args)
{
Scanner siri = new Scanner(System.in);
int num, num2;
System.out.println("Type in a number and I'll square root it");
System.out.print("Number: ");
num = siri.nextInt();
if (num == 0)
System.out.println("You can not enter 0, just for that you dont get to play anymore");
while (num != 0 && num < 0)
{
if (num < 0)
{
System.out.println("You can not enter a negative number!");
System.out.print("Try again: ");
num = siri.nextInt();
if (num > 0)
{
System.out.println(Math.sqrt(num));
System.out.println(" ");
}
}
num++;
}
}}
Picture of the output