Only two lines need to be changed:
double result = Math.log( value ); System.out.println("logarithm: " + result );
sqrt()
MethodHere is sample output from the (unmodified) program:
C:\chap11>java SquareRoot Enter a double: 3 square root : 1.7320508075688772
It is OK to enter a number without a decimal point (as the "3" above) for floating point IO. Java converts it to the correct type.
Here is some of the documentation for the method sqrt()
:
static double sqrt(double a) Returns the correctly rounded positive square root of a double value.
This was copied from the Java documentation you probably have in your Java Development Kit subdirectory. It also can be found at: java.sun.com