-3

I'm trying to write a Java program that can take values and put them into a formula involving electron. How can I calculate e^x in Java?

  • 1
    See this [article](https://www.geeksforgeeks.org/program-to-efficiently-calculate-ex/). – Makdous May 05 '20 at 14:37
  • Does this answer your question? [Calculate e^x without inbuilt functions in Java](https://stackoverflow.com/questions/26140238/calculate-ex-without-inbuilt-functions-in-java) or [Recursively calculate e^x with Java](https://stackoverflow.com/questions/22065279/recursively-calculate-ex-with-java-using-maclaurin-series). – U880D May 05 '20 at 15:02
  • @U880D didn't answer my question – berlianafd May 05 '20 at 15:41
  • @Makdous can't be opened – berlianafd May 05 '20 at 15:41

3 Answers3

1

you can use java.lang.Math.exp() method to calculate e^x. here is an example

`
public static void main(String[] args) 
{
    double a = 2.0;
    System.out.println(Math.exp(a));
}
//output = 7.38905609893065
`

you can read more about this using this link. https://www.javatpoint.com/java-math-exp-method

0

You could use Math.exp().

Example:

import java.lang.Math;

// inside main
Math.exp(1.0);        // e^1
Math.exp(1.6);        // e^1.6
Animesh Sahu
  • 7,445
  • 2
  • 21
  • 49
-1
import java.lang.Math; 

class Answer { 

    // driver code 
    public static void main(String args[]) 
    { 
        double a = 30; 
        double b = 2; 
        System.out.println(Math.pow(a, b)); 

        a = 3; 
        b = 4; 
        System.out.println(Math.pow(a, b)); 

        a = 2; 
        b = 6; 
        System.out.println(Math.pow(a, b)); 
    } 

//you can use Math.pow(e,x);
papaya
  • 1,505
  • 1
  • 13
  • 26