go to previous page   go to home page   go to next page hear noise highlighting

Answer:

Only two lines need to be changed:

double result = Math.log( value );

System.out.println("logarithm: " + result );

sqrt() Method

Here is sample output from the (unmodified) program:

C:\chap13>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 I/O. 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 on-line Java documentation. Search for "sqrt Java" with a search service (like Google) when you need it.

https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html.


QUESTION 13:

Inspect the documentation. What is the type of the argument expected by sqrt()?

What is the type of value returned by sqrt()?

Is sqrt() a static method?


go to previous page   go to home page   go to next page