// This program reads in a value and outputs its square root. // It outputs an error message if the data value is negative. // Barry Cornelius, 3 June 2000 import java.io. BufferedReader; import java.io. InputStreamReader; import java.io. IOException; public class Sqrt2 { public static void main(final String[] pArgs) throws IOException { final BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Type in a value: "); System.out.flush(); final String tLine = tKeyboard.readLine(); final double x = Double.parseDouble(tLine); if (x>=0.0) { final double tSqrtX = Math.sqrt(x); System.out.print("The square root of this value is: " + tSqrtX); } else { System.out.print("This value is negative"); } System.out.println(); } }