Advertisement
CamiloCastilla

Untitled

Dec 9th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         System.out.println("SQUARE ROOT!");
  7.         System.out.println("Enter a number:");
  8.         Scanner keyboard = new Scanner(System.in);
  9.         int num = keyboard.nextInt();
  10.  
  11.         if (num < 0)
  12.  
  13.             do {
  14.                 System.out.println("You can't take the square root of a negative number, silly.");
  15.                 System.out.println("Try Again");
  16.                 num = keyboard.nextInt();
  17.  
  18.             } while (num > 0);
  19.             double num2 = Math.sqrt(num);
  20.             System.out.println("The square root of " + num + " is " + num2);
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement