×

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

Hello Program in Java

Hello Program in Java The Hello program in Java displays the word Hello on the console. It is the basic program in Java. In this section, we will learn different ways...

3 minutes read.

Java Class Keyword

We know that java is object-oriented programming language which contains the essential key concepts such as classes and objects etc to have clear idea about the object-oriented programming.Java is mainly...

3 minutes read.

Java Byte intValue() method

The intValue()  method of Java Integer class returns an int value for this Integer.  Syntax public int intValue()  Parameters NA  Specified by This method is specified by intValue in class Number  Return Value This method returns the numeric...

1 minute read.

Sleeping Barber Problem in Java

The barbershop in this issue has one barber, one barber chair, and N chairs for customers in the waiting area. We may demonstrate the issue by keeping with the original...

6 minutes read.

What are Array strings in Java?

In normal programming, An array is a group and a collection of identical forms of data that are stored in a sequential memory region and may be accessed using their...

4 minutes read.

Java String length() method

Java String length() method returns length of the characters in a String. Syntax: public int length() Returns It returns length of the characters Java String length() method example 1          public class JavaStringLengthEx1  ...

1 minute read.

Java Characters

Normally, when we work with characters, we use primitive data types char. When we have to work with the objects of char, we use Character class. Character class has many important...

2 minutes read.

XOR Binary Operator in Java

One of the various Bitwise operators in Java is ava XOR. If two boolean operands are given, the XOR (also known as exclusive OR) returns true. When both of the...

4 minutes read.

Longest Odd Even Subsequence in Java

In order to solve the Java problem known as the longest odd-even subsequence, one must identify a sequences in a non-negative array having size s that alternately includes odd and...

6 minutes read.

Java Program to Add Digits Until the Number Becomes a Single Digit Number

We will develop Java programme that increase a number's digit count in order to reduce it to one. The issue is also known as the digit root problem. Example Consider the case where...

3 minutes read.

Java Map Generic

Java arrays maintain an ordered collection of things, and the index can be used to access the data (an integer). Unlike HashMap, which stores data as a Key/Value pair. We...

3 minutes read.

Java Math abs() Method

The abs() method of Math class returns the absolute value of the argument where the argument can be int, double, float, long. Syntax public static int abs(int a) public static float abs(float a) public...

2 minutes read.

Bubble Sort in Java

Bubble Sort in Java Bubble sort isalso known as sinking sort. It is one of the simplest sorting algorithms. In the bubble sort algorithm, the given array is traversed from left...

5 minutes read.

Java Extends vs Implements

Java: We known that the java is a pure object oriented programming language. Java programming language consists of many features such as portable, plat form independence, secured, robust, simple, architecture neutral,...

4 minutes read.

Java Sort String

In this article, you will be acknowledged about how to sort a string in Java. Introduction Firstly, let us revise what is string Strings are collections of characters that are frequently used in...

4 minutes read.

Array Slicing in Java

Array slicing is a method in Java for obtaining a subarray of a specified array. Assume a[] is an array. It contains eight items indexed from a[0] to a[7].a[] =...

3 minutes read.

Centered Square Numbers in Java

In this tutorial, we will understand how to check the number is a centered square number. It is one of the prevalent interview questions of IT companies. Firstly, we will...

3 minutes read.

Minimum Difference Between Groups of Size Two in Java

There is given an array with various integers in it. The goal is to divide the elements into distinct groups, each of which has just two, so that the difference...

3 minutes read.

Lombok Java

What is Lombok java? A well-liked and widely-used Java framework that is used to reduce or eliminate boilerplate code is called Project Lombok. Both time and effort are saved. We may...

7 minutes read.

Three-way operator in Java

The ternary operator in Java is the only conditional operator that takes three operands. It's a popular one-line substitute for the if-then-else expression among Java programmers. If-else clauses can be...

3 minutes read.