×

Java Math exp() Method

The exp() method of Math class returns Euler’s number(e) raised to the power of a double value.

Syntax:

public static double exp(double a)

Parameters:

The parameter ‘a’ represents the exponent e.

Return Value:

The exp () method returns the value ea, where e represents the base of the natural logarithms.

Special cases of the exp() method are as follows:

  • It returns NaN, is the argument passed is NaN.
  • It returns positive infinity, if the argument passed is positive infinity.
  • It returns positive zero, if the argument passed is negative infinity.

Example 1:

public class JavaMathExpExample1 {
    public static void main(String[] args) {
        double a=0;
        //returns the value for e raised to power 0 (e0)
        System.out.println("e raised to power "+ a+" = "+Math.exp(a));
    }
}

Output:

e raised to power 0.0 = 1.0

Example 2:

public class JavaMathExpExample2 {
    public static void main(String[] args) {
        double a=-9;
        //returns the value for e raised to power 9 (e9)
        System.out.println("e raised to power "+ a+" = "+Math.exp(a));
    }
}

Output:

e raised to power -9.0 = 1.2340980408667956E-4

Example 3:

public class JavaMathExpExample3 {
    public static void main(String[] args) {
        double a=-9/0.0d;
       //It returns positive zero, if the argument passed is negative infinity
        System.out.println("e raised to power "+ a+" = "+Math.exp(a));
    }
}

Output:

e raised to power -9.0 = 1.2340980408667956E-4

Example 4:

public class JavaMathExpExample4 {
    public static void main(String[] args) {
        double a=9/0.0d;
        //It returns positive infinity, if the argument passed is negative
infinity
        System.out.println("e raised to power "+ a+" = "+Math.exp(a));
    }
}

Output:

e raised to power Infinity = Infinity

Example 5:

public class JavaMathExpExample5 {
    public static void main(String[] args) {
        double a=0.0d/0.0d;
        //It returns NaN, is the argument passed is NaN
        System.out.println("e raised to power "+ a+" = "+Math.exp(a));
    }
}

Output:

e raised to power NaN = NaN

Related Topics

How to Convert int to long in Java

How to Convert int to long in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

2 minutes read.

Duodecimal in Java

Duodecimal is a notation style in which a number with a base of 12 is referred to be a duodecimal number. In Java, we can use to convert duodecimal integers...

2 minutes read.

Java Exception Propagation

Java Exception Propagation When an exception is being thrown from the peak of the stack and not getting caught, it runs down the stack to the previous method, which is sitting...

3 minutes read.

Read the XLSX file in Java

Excel files contain cells; reading an excel file in Java differs from reading a word file. JDK doesn't have a direct API that can read or write Word or Excel...

3 minutes read.

How to take String Input in Java

There are various ways to take String input in Java. In this section, we are going to discuss how to take String input in Java. There are following ways to...

5 minutes read.

Zebra Puzzle Problem in Java

Complex puzzles like the zebra puzzle demand a lot of work and mental training to complete. Because it was created by renowned German scientist Albert Einstein, it is also sometimes...

10 minutes read.

Java extend multiple classes

In Java, what does extend mean? One of several Java inheritance keywords is extended, meaning we pass all or most of the Parent class's characteristics through to the Child class. The...

3 minutes read.

Java Code Optimization

We encounter the idea of optimization while working on any Java application. It is essential that the code we write is not only clear and error-free but also optimized, meaning...

9 minutes read.

For Loop Program in Java

For Loop Program in Java The for-loop program in Java is written when we want a particular set of statements to be executed repeatedly until the given criteria/ condition is met....

8 minutes read.

Cast Operator in Java

A cast is a unique operator that completely converts one type of data into another. Casts are unary operators and have the same priority as other unary operators. Type casting in...

3 minutes read.

Compile time vs Runtime in java

Introduction: This article will discuss compile time vs. runtime in java. Compile time and runtime are two programming terms utilized in software improvement. Compile time is when the source code is...

3 minutes read.

How to add 24 Hours to Date in Java?

In this tutorial, we will learn how to add 24 hours to the local or current date in Java language. We will begin our topic with basic concepts and would...

2 minutes read.

Rehashing in Java

The most crucial idea mostly in the data structure is hashing, which is utilized to change a particular key into some other value. The hash function can be used to...

7 minutes read.

Intersection Point of two linked list in Java

In this article, you will be very well acknowledged about how to achieve the intersection point of two linked list in Java. There are several approaches to obtain. Surely each...

8 minutes read.

Differences and Similarities between HashSet, LinkedHashSet and TreeSet in Java

HashSet Class: The HashSet is a class that executes the Setpoint of interaction. It is utilised to store the items in a hashtable; a hashtable is an information structure which holds...

10 minutes read.

How to Convert char to int in Java

How to Convert char to int in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

3 minutes read.

Java Binary Tree

The non-linear data structure known as a binary tree is a type of tree, and because it stores data in a hierarchical manner, it is mostly utilised for finding and...

7 minutes read.

Java Integer sum() method

The sum() method of Java Integer class add the two specified integers values. It returns the same result as given by + operator. Syntax public static int sum (int a, int b)  Parameters The...

1 minute read.

Repdigit Numbers in Java

A combination of repeated and digit, the term is. A repdigit, also known as a monodigit or a positional number system, is a natural number in recreational mathematics made up...

3 minutes read.

Class memory in Java

Anything specifically defined in the Java code is stored either inside the heap or the stack, which is particularly significant. Stack and heap are the two kinds of memory available...

6 minutes read.