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 N Niraj_Pandey Follow Improve Article Tags : Java java-math Practice Tags : Java Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOPs & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial15+ min readSynchronization in Java10 min readFile Handling in Java5 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like