Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Square root!");
- double num;
- do{
- System.out.println("Enter a number(enter zero to exit): ");
- num = keyboard.nextInt();
- if (num <0){
- System.out.println("You can't take the square root of a negative number.");
- System.out.println("Enter a number (enter zero to exit): ");
- num = keyboard.nextInt();
- }else{
- System.out.println(Math.sqrt(num));
- }
- }while (num >= 0);
- System.out.println("Program closing");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement