Home >>Java Math Methods >Java Math.log() method

Java Math.log() method

Java Math.log() method

The Math.log() Method in Java Math is used to find out any number's Logarithmic Value. This method returns a double value as a parameter of the natural logarithm (base e).

Syntax

public static double log(double x)

Parameters

x= This parameter is used for a value entered by user

Returns

It is used to returns the value In a, the natural logarithm of a.

  1. This method returns the logarithm of a given value if the argument is Positive value.
  2. This method will return -1 if the statement is Negative value.
  3. If the argument is not Number (-1), -1 will return this form.
  4. If Positive Infinity is the statement, then this method returns Positive Infinity.
  5. This method returns Negative Infinity if the argument is positive or negative Zero.

Java Math.log() Method Example 1


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double a = 12.5;  
        System.out.println(Math.log(a));  
    }  
}  

Output:
2.5257286443082556

Java Math.log() Method Example 2


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double a = -23.7;  
        System.out.println(Math.log(a));  
    }  
}  

Output:
NaN

No Sidebar ads