/**
 * SquareRootCalculator2.java
 *
 * Computer Science S-111
 * 
 * This alternate version of the SquareRootCalculator program
 * corrects the compile-time error in SquareRootCalculator2Incorrect.java.
 */

import java.util.*;

public class SquareRootCalculator2 {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        
        System.out.print("enter a positive int: ");
        int num = console.nextInt();
        
        // Declaring sqrt here allows it to be used in both the
        // true and false blocks, and in the println that follows them.
        double sqrt;
        if (num < 0) {
            System.out.println("number is negative;" 
              + " using its absolute value");
            sqrt = Math.sqrt(num * -1);
        } else {
            sqrt = Math.sqrt(num);
        }
        System.out.println("square root = " + sqrt);    
    }
}
