EN
Java - Math.exp() method example
0 points
Math.exp()
is a static method that takes only one parameter and returns exponential function value in the range 0
(exclusive) to +Infinity
.
xxxxxxxxxx
1
public class MathExample {
2
3
public static void main(String[] args) {
4
System.out.println( Math.exp( -100 ) ); // 3.720075976020836E-44
5
System.out.println( Math.exp( -1 ) ); // 0.36787944117144233
6
System.out.println( Math.exp( 0 ) ); // 1.0
7
System.out.println( Math.exp( 1 ) ); // 2.718281828459045
8
System.out.println( Math.exp( 100 ) ); // 2.6881171418161356E43
9
10
System.out.println( Math.exp( Double.NEGATIVE_INFINITY ) ); // 0.0
11
System.out.println( Math.exp( Double.POSITIVE_INFINITY ) ); // Infinity
12
System.out.println( Math.exp( Double.NaN ) ); // NaN
13
}
14
}
Syntax |
xxxxxxxxxx 1 package java.lang; 2 3 public final class Math { 4 5 public static double exp(double number) { ... } 6 7 }
|
Parameters | number - double value (primitive value). |
Result |
Exponential function value of a number in the range If the value can not be calculated |
Description |
|
xxxxxxxxxx
1
public class MathExample {
2
3
static void printLine(double y1, double y2, double dy, String character) {
4
StringBuilder line = new StringBuilder();
5
for (double y = y1; y < y2; y += dy) {
6
line.append(" ");
7
}
8
System.out.println(line + character);
9
}
10
11
public static void main(String[] args) {
12
double x1 = -4; // beginning of sine chart
13
double x2 = +2.8; // end of sine chart
14
15
double y1 = -1.0;
16
double y2 = +10.0;
17
18
double xSteps = 25;
19
double ySteps = 60;
20
21
double dx = (x2 - x1) / xSteps; // x axis step
22
double dy = (y2 - y1) / ySteps; // y axis step
23
24
for (double rad = x1; rad < x2; rad += dx) {
25
double y = Math.exp(rad);
26
if (y <= y1 || y >= y2) {
27
System.out.println(" ");
28
} else {
29
printLine(y1, y, dy, "+");
30
}
31
}
32
}
33
}
Output:
xxxxxxxxxx
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+