exp() Method in Java
Table of Content:
Description
This java tutorial shows an example of how to use the exp(double) method of Math class under java.lang package. This method returns the Euler's number raised to the power of double value specified as a method argument.
The method returns the base of the natural logarithms, e, to the power of the argument.
Syntax
double exp(double d)
Parameters
Here is the detail of parameters ?
-
d ? Any primitive data type.
Return Value
-
This method returns the base of the natural logarithms, e, to the power of the argument.
The exp(double a) method simply returns the value e a, where e is the base of the natural logarithms in consideration the following cases:
- If the argument is NaN, the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is negative infinity, then the result is positive zero.
Example
public class MathExp { public static void main(String args[]) { double x = 11.635; double y = 2.76; System.out.printf("The value of e is %.4f%n", Math.E); System.out.printf("exp(%.3f) is %.3f%n", x, Math.exp(x)); } }
The value of e is 2.7183 exp(11.635) is 112983.831 Press any key to continue . . .
Example
This java example source code demonstrates the use of exp(double a) method of Math class. Basically we just raised the e value into an exponent and print the output.
import static java.lang.System.*; import java.util.Scanner; /* * This example source code demonstrates the use of * exp(double a) method of Math class */ public class MathEXP { public static void main(String[] args) { // declare the exponent to be used double exponent = 3; // raise e to exponent declared double expValue = Math.exp(exponent); out.println("Value = "+expValue); } }
Running the exp(double a) method example source code of Math class will give you the following output.
The value of e is 2.7183 exp(11.635) is 112983.831 Press any key to continue . . .
Find exponential value of a number using Math.exp
/* Find exponential value of a number using Math.exp This java example shows how to find an exponential value of a number using exp method of Java Math class. */ public class FindExponentialNumberExample { public static void main(String[] args) { /* * To find exponential value of a number, use * static double exp(double d) method of Java Math class. * * It returns e raised to argument value. */ System.out.println("Exponential of 2 is : " + Math.exp(2)); } }
Exponential of 2 is : 7.38905609893065 Press any key to continue . . .