×

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

Print Pencil Shape Pattern in Java

Another pattern made from asterisk symbols that use loops and other logical concepts is the pencil pattern. It is usually requested to draw a pattern using a program. To write the...

6 minutes read.

How to Create a Generic List in Java?

Generics are types that have parameters. The goal is to make it possible for methods, classes, and interfaces to take type (Integer, String, etc., and user-defined types) as a parameter....

4 minutes read.

Java Boolean equals() method

The equals() method of Java Boolean class returns a Boolean value true if the specified argument is not null and is same as this object, else it returns false. Syntax public boolean...

2 minutes read.

Access Modifier in Java

The access modifiers in java are used to change the accessibility and scope of a method, constructor, class, and fields. If you are aware of C++ language, when we declare any member...

2 minutes read.

Java String getChars() Method

Java String getChars() method copies characters from current String to the destination character array . Syntax: public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex) Parameters: srcBegin - index of the first character...

1 minute 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.

Java gc()

Garbage collection Java language provides different ways to perform the task of memory management. In Java, objects are declared and assigned references. Once lifeof an object is completed it is dereferenced...

4 minutes read.

Types of Garbage Collector in Java

Garbage collection is a Java feature that offers automatic memory management. The JVM is in charge of it. The programmer does not have to handle object creation and deallocation. We...

3 minutes read.

Java Print Writer

PrintWriter: It is used to write output data from the file. It is the class of Java.io package. It inherits the properties of the Writer class. Writer Class: It is a class of...

4 minutes read.

How to find length of integer in Java

We can find the length of the integer in many ways. The length of an integer is defined as the count of the number of digits for the given integer. These...

5 minutes read.

How to Convert Integer to String in Java

How to Convert int to String in Java It is used when you want to convert an integer to String. You can convert int to String by using the following methods: Using...

3 minutes read.

Java String toLowerCase() methods

Java String toLowerCase() method is used to convert all the characters of the String into lower case. Syntax: public String toLowerCase()              public String toLowerCase(Locale locale) Returns: It returns Lower...

1 minute read.

nth Prime Number in Java

A number is considered prime if only divisible by one and itself. Prime numbers include, for example, 2, 3, 5, 7, 11, etc. In looking at it another way, a...

5 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.

How to Convert String to float in Java

How to Convert String to Float in java It is used if you want to perform mathematical operations on the string that contains float number. You can convert String to float...

3 minutes read.

Read JSON file in Java

 To know about reading a JSON file in Java first we must know about the JSON file. JSON: JSON is “JavaScript Object Notation”. The JSON is the simple format for storing and...

3 minutes read.

Static Array in Java

In this tutorial, we will study static arrays in Java. An array is a data structure that is of great importance in any programming language. It is classified into two...

3 minutes read.

How to download Eclipse for Java

Introduction: We write a java program, and when we want to run it, we need software to run it. Eclipse is a kind of software used to execute a JavaFX...

3 minutes read.

How to open the Java control panel

The many methods for launching the Java control panel will be covered in this section. We will also go through how the Java Control Panel can be used. Java Control Panel The...

2 minutes read.

Creating API Document Javadoc tool

The JavaDoc utility is a document generator tool written in Java that generates standard documentation in HTML format. It parses declarations and documentation in a source file collection that describes...

3 minutes read.