Java Basic Examples

Calculate logarithm value using log method of Java Math class

This example shows how to calculate logarithm values using log() method of Java Math class.

How to calculate natural logarithm value in Java?

Use log() static method of Java Math class to calculate logarithm value in Java.

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

Output

How to calculate log value base 10 in Java?

log() method of Java Math class uses base e. If you want to calculate log base 10 use 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 in Java?

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

Output

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

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.

Tags

About the author

rahimv

rahimv

rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

Add Comment

Your email address will not be published. Required fields are marked *