Java Math log() method with example Last Updated : 04 Apr, 2023 Comments Improve Suggest changes Like Article Like Report 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 : public static double log(double a) Parameter : a : User input Return Type: This method returns the value ln a. Example 1: To show the working of java.lang.Math.log() method. java // 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 System.out.println(Math.log(a)); // positive infinity as argument, output Infinity System.out.println(Math.log(b)); // positive zero as argument, output -Infinity System.out.println(Math.log(c)); // positive double as argument System.out.println(Math.log(d)); } } Output:NaN Infinity -Infinity 4.978497702968366 Example 2: Java import java.io.*; class GFG { public static void main(String[] args) { double number = 10.0; double result = Math.log(number); System.out.println(result); } } Output2.302585092994046 Comment More infoAdvertise with us Next Article Java Math log() method with example N Niraj_Pandey Follow Improve Article Tags : Java java-math Practice Tags : Java Similar Reads Java Math exp() method with Example The Math.exp() method is a part of the java.lang.Math class. This method is used to calculate the value of Euler's number e raised to the power of a specified exponent. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.Sp 2 min read Java Math expm1() method with Example In Java, the Math.expm1() method is used to calculate e^x - 1. This method is used when we have to deal with small values of x close to zero, as it avoids errors that can occur when calculating Math.exp(x) - 1.Note: e is the base of natural logarithms, and x is the argument passed to the method.In t 2 min read Math pow() Method in Java with Example The Math.pow() method in Java is used to calculate a number raised to the power of some other number. It is part of the java.lang.Math class and is widely used in mathematical computations, scientific calculations, and algorithmic problems. This function accepts two parameters and returns the value 3 min read Logger log() Method in Java with Examples The log() method of Logger is used to Log a message. If the logger is currently enabled for the given message level which is passed as parameter then a corresponding LogRecord is created and forwarded to all the registered Output Handler objects. But in logger class, there are seven different log() 6 min read File length() method in Java with Examples The length() function is a part of File class in Java . This function returns the length of the file denoted by the this abstract pathname was length.The function returns long value which represents the number of bytes else returns 0L if the file does not exists or if an exception occurs. Function s 2 min read Year length() method in Java with Examples The length() method of Year class in Java is used to return the length of this year object's value in number of days. There can be only two possible lengths of Year, 365(Non-leap years) and 366(Leap years). Syntax: public int length() Parameter: This method does not accepts any parameter. Return Val 1 min read Logger fine() method in Java with Examples The fine() method of a Logger class used to Log a FINE message. This method is used to pass FINE types logs to all the registered output Handler objects. FINE, FINER and FINEST provide tracking information as when what is happening/ has happened in our application. FINE displays the most important m 3 min read LogManager reset() method in Java with Examples The reset() method of java.util.logging.LogManager is used to reset the logging configuration. This method throws SecurityException if the exception condition occurs, as given below Syntax: public void reset() throws SecurityException Parameters: This method does not accepts any parameter. Return Va 1 min read List get() method in Java with Examples The get() method of List interface in Java is used to get the element present in this list at a given specific index. Example:Java// Java Program to demonstrate List // get() Method import java.util.*; class Main { public static void main (String[] args) { // Create a List List<Integer> a=new 2 min read LongAccumulator get() method in Java with Examples The java.LongAccumulator.get() is an inbuilt method in java that returns the current value of the LongAccumulator object. Syntax: public long get() Parameters: This method does not accepts any parameter. Return Value: The method returns the current value of the LongAccumulator object. Below programs 1 min read Like