Calculating a Logarithm


double logValue = Math.log(125.5);



In this phrase, we use the log() method of the java.lang.Math class to calculate the logarithm of the parameter passed in. We pass in a value of double type, and the return value is also a double value. The log() method calculates the natural logarithm, using base e, where e is the standard value of 2.71828.

JDK1.5 added a new method to the Math class for directly calculating a base 10 logarithm. This is the log10() method. Similar to the log() method, this method takes a double input parameter, and returns a double result type. We can use this method to easily calculate a base 10 logarithm as follows:

double logBase10 = Math.log10(200);





JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net