Java log() Method

Java Number类Java Number Class


The log() method is used to return the natural logarithm (base e) of the argument.

Syntax

double log(double d)

Parameters

  • d-- Any primitive data type.

Return Value

Returns the natural logarithm of the argument.

Example

public class Test{
    public static void main(String args[]){
        double x = 11.635;
        double y = 2.76;

        System.out.printf("e 的值为 %.4f%n", Math.E);
        System.out.printf("log(%.3f) 为 %.3f%n", x, Math.log(x));
    }
}

Compiling the above program will produce the following output:

e 的值为 2.7183
log(11.635) 为 2.454

Java Number类Java Number Class

Other Extensions