- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get natural logarithm value using Math.log in Java
To obtain the natural log of a number, we use the java.lang.Math.log() method. The Math.log() method returns the natural logarithm i.e. log to the base e of a double value. If the value passed is NaN or negative, the result is NaN. If the value passed is positive infinity, then the value returned is positive infinity. When the parameter is positive zero or negative zero, then negative infinity is returned.
Declaration - The java.lang.Math.log() method is declared as follows
public static double log(double a)
where a is a value whose natural logarithm is to be found.
Let us see a program to get the natural logarithm of a number in Java using the Math.log() method
Example
import java.lang.Math; public class Example { public static void main(String[] args) { // declaring and initializing two double values double x = 300.01d; double y = 290.344d; // printing their natural logarithms System.out.println("Natural logarithm of "+ x + " is " + Math.log(x)); System.out.println("Natural logarithm of "+ y + " is " + Math.log(y)); } }
Output
Natural logarithm of 300.01 is 5.703815807433991 Natural logarithm of 290.344 is 5.671066426889541
- Related Articles
- How to get Natural logarithm of 10 in JavaScript?
- How to get Natural logarithm of 2 in JavaScript?
- Get the base 10 logarithm of a value in Java
- Compute the Natural Logarithm in Python
- How to get the natural logarithm (base E) of a number in JavaScript?
- Compute the natural logarithm with scimath in Python
- Compute the Natural logarithm for complex-valued input in Python
- Using logarithm in SAP ABAP
- Math.log() function in JavaScript
- Math.Log() Method in C#
- Get ceiling value of a number using Math.ceil in Java
- Get exponential value of a number using Math.exp in Java
- Get floor value of a number using Math.floor in Java
- Return the natural logarithm of one plus the input array element-wise in Numpy
- Compute the sign and natural logarithm of the determinant of an array in Python

Advertisements