Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Java Math log() method with example

  • Difficulty Level : Easy
  • Last Updated : 23 Mar, 2018

The java.lang.Math.log() method returns the natural logarithm (base e) of a double value as a parameter. There are various cases :

  • 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 :

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

public static double log(double a)

Parameter :

a : User input

Return :

This method returns the value ln a.

Example :To show working of java.lang.Math.log() method.

// Java program to demonstrate working
// of java.lang.Math.log() method
import java.lang.Math;
class Gfg {
    // driver code
    public static void main(String args[])
        double a = -2.55;
        double b = 1.0 / 0;
        double c = 0, d = 145.256;
        // negative integer as argument, output NAN
        // positive infinity as argument, output Infinity
        // positive zero as argument, output -Infinity
        // positive double as argument
My Personal Notes arrow_drop_up
Recommended Articles
Page :