sqrt() Method

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

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:/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 can download from java.sun.com. If you don't have this on your computer, you can search for "sqrt Java" with a search service (like Google) and find it.

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?