Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java log() Method

Java log() Method

Java Number ClassThe Java Number class


The log() method returns the natural logarithm (base e) of the argument.

Syntax



double log(double d)

Parameters

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));

    }

}

Compile the above program; the output is:



e 的值为 2.7183

log(11.635) 为 2.454


Java Number ClassThe Java Number class