Advertisement
lol1234561

Untitled

Mar 29th, 2023
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner keyboard = new Scanner(System.in);
  5.         System.out.println("Square root!");
  6.         double num;
  7.         do{
  8.             System.out.println("Enter a number(enter zero to exit): ");
  9.             num = keyboard.nextInt();
  10.            if (num <0){
  11.                System.out.println("You can't take the square root of a negative number.");
  12.                System.out.println("Enter a number (enter zero to exit): ");
  13.                num = keyboard.nextInt();
  14.            }else{
  15.                System.out.println(Math.sqrt(num));
  16.            }
  17.        }while (num >= 0);
  18.  
  19.         System.out.println("Program closing");
  20.  
  21.  
  22.  
  23.  
  24.  
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement