📅  最后修改于: 2023-12-03 15:31:31.526000             🧑  作者: Mango
The Math.log()
method in Java is used to find the natural logarithm of a number. It returns the value of the natural logarithm (base e) of the given argument.
public static double log(double num)
The log()
method takes a single parameter of type double, which represents the number whose natural logarithm is to be found.
The log()
method returns the natural logarithm of the given number, rounded to the nearest double value.
public class Example {
public static void main(String[] args) {
double x = 5.0;
double result = Math.log(x);
System.out.println("The natural logarithm of " + x + " is " + result);
}
}
Output:
The natural logarithm of 5.0 is 1.6094379124341003
log()
method is 0.0, then the method returns -Infinity
.log()
method is negative, then the method returns NaN
(Not a Number).In conclusion, the Math.log()
method is a useful tool to find the natural logarithm of a number in Java. It can be used in various mathematical calculations where the natural logarithm is required.