Skip to content

Calculate logarithm value using log method of Java Math class

Calculate logarithm value example shows how to calculate natural logarithm values using the log method of Java Math class.

How to calculate natural logarithm value in Java?

We can use the static log method of the Math class to calculate logarithm values in Java.

This method returns the natural logarithm value (base e) of the argument double number.

Output

How to calculate log value base 10 in Java?

Thelog method of the Math class uses base e. If you want to calculate log base 10 use the following code.

a) Java version 1.4 and below

Output

b) Java version 1.5 and above

Java version 1.5 introduced a new method log10 which calculates log value using base 10.

Output

How to calculate log value base 2?

Use the following code to calculate log value base 2 in Java.

Output

This example is a part of the Java Math class tutorial with examples.

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.