Java.lang Package Classes

Java StrictMath - log() Method



The java.lang.StrictMath.log() method returns the natural logarithm (base e) of a given number. In special cases it returns the following:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is negative infinity.

Syntax

public static double log(double a)

Parameters

a Specify the number.

Return Value

Returns the natural logarithm of a given number.

Exception

NA.

Example:

In the example below, log() method is used to calculate the natural logarithm of a given number.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(StrictMath.log(10)); 
  System.out.println(StrictMath.log(50)); 
  System.out.println(StrictMath.log(100));     
 }
}

The output of the above code will be:

2.302585092994046
3.912023005428146
4.605170185988092

❮ Java.lang - StrictMath