Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

Java exp Function

The Java exp Function is one of the Java Math functions, which is useful to return E raised to the power of double value. Where E is Euler’s number, and it is approximately equal to 2.71828.

Java exp Function Syntax

The basic syntax of the Math.exp in Java Programming language is as shown below.

static double exp(double number); //Return Type is Double

// In order to use in program: 
Math.exp(double number);

Number: It can be a double value or a valid numerical expression, and it represents the exponent value.

  • If the number argument is a positive or negative double value, the Math.exp function will return the output.
  • If the number argument is not a number, the Java Math.exp function will return NaN.
  • When the number argument is positive infinity, the Math.exp function will return Positive Infinity as the output.
  • If it is negative infinity, the Math.exp function will return Positive Zero as output.

For example, if we specify the expression as Math.exp (2.00). It means e² ==> 2.718² ==> 7.38

Java exp Function Example

In this Java program, we use the Java Math.exp Function to calculate the power of Euler’s number E of both positive and negative values and display the output.

// Java Math.exp Function

package MathFunctions;

public class ExpMethod {
	public static void main(String[] args) {
		double a = Math.exp(10.9666 - 14.9865 + 10.9852);
		System.out.println("Math.Exp Result = = " + a);	

		System.out.println("\nMath.Exp Result of Positive Number = " + Math.exp(4.25));
		System.out.println("Math.Exp Result of Positive Number = " + Math.exp(6.95));
		
		System.out.println("\nMath.Exp Result of Negative Number = " + Math.exp(-2.85));
		System.out.println("Math.Exp Result of Negative Number = " + Math.exp(-10.25));
		
		System.out.println("\nMath.Exp Result = " + Math.exp(1));
		System.out.println("Math.Exp Result = " + Math.exp(-1));
	}
}
Java exp Function 1

First, we declared a variable of type Double and performed the Math.exp function directly on expression.

double a = Math.exp(10.9666 - 14.9865 + 10.9852);
System.out.println("Math.Exp Result = = " + a);

Next, we used the Math.exp Function directly on Positive double values. Here, Math.exp(4.25) means (2.71828)^4.25

System.out.println("\nMath.Exp Result of Positive Number = " + Math.exp(4.25));
System.out.println("Math.Exp Result of Positive Number = " + Math.exp(6.95));

Here, we used the Java exp Function directly on Negative double values.

System.out.println("\nMath.Exp Result of Negative Number = " + Math.exp(-2.85));
System.out.println("Math.Exp Result of Negative Number = " + Math.exp(-10.25));

Next, we used the Math.exp Function directly on both Positive and Negative double values.

System.out.println("\nMath.Exp Result = " + Math.exp(1));
System.out.println("Math.Exp Result = " + Math.exp(-1));

Java exp on Array example

In this Java program, we return the Euler’s number E raised by the power of bulk data. Here, we are going to declare an array of double type and using the Java Math.exp function of array elements.

package MathFunctions;

public class ExpMethodOnArrays {
	public static void main(String[] args) {
		
		double [] myArray = {-1.69, 5.98, 4.21, -3.9999, 6.879, 4.4897};

		for (int i = 0; i < myArray.length; i++) {
			System.out.format("Math.Exp Result of Array Element = %.2f\n", Math.exp(myArray[i]));
		}
	}
}
Java exp Function 2

We used the Java For Loop to iterate the Array. Within the exp For Loop, we initialized the i value as 0. Next, the compiler will check for the condition (i < myArray.length). As along the condition is True statement inside the for loop will be executed.

TIP: myArray.length finds the length of the Java array.

for (int i = 0; i < myArray.length; i++) {

Here, we used the exp Math function directly inside the System.out.format statement. Here, the compiler will call the Math.exp method ( static double exp(double number) ) to find the corresponding exp value and print the output.

System.out.format("Math.Exp Result of Array Element = %.2f\n", Math.exp(myArray[i]));

NOTE: To use Math.exp on a single item, then use: Math.exp(myArray[index_position])

Java exp function on Arraylist example

In this Java program, we are going to declare an arraylist of double type and return the Euler’s number E raised by the power of list elements.

package MathFunctions;

import java.util.ArrayList;

public class ExpMethodOnArrayList {
	public static void main(String[] args) {
		
		ArrayList<Double> myList = new ArrayList<Double>(5);
		myList.add(-2.5);
		myList.add(2.5);
		myList.add(4.25);
		myList.add(-4.25);
		myList.add(5.00);
		
		for (double x : myList) {
			System.out.println("Math.Exp Result of ArrayList =  " + Math.exp(x));
		}
	}
}
Java exp Function 3

We used the For Loop to iterate the double values in ArrayList

for (double x : myList) {

Here, the compiler will call the java math exp method ( static double exp(double x) ) to find the corresponding exp value and print the output.

System.out.println("Math.Exp Result of ArrayList =  " + Math.exp(x));

Filed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021· All Rights Reserved by Suresh.
About | Contact | Privacy Policy