forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx5.java
More file actions
30 lines (26 loc) · 650 Bytes
/
Copy pathEx5.java
File metadata and controls
30 lines (26 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class Ex5 {
public static void main(String[] args) {
check(-0.1);
}
public static void check(double x) {
if (Math.abs(x) <= 100) {
System.out.println(x + "\t" + myexp(x) + "\t" + eToTheX(x));
x = x * 10;
check(x);
}
}
public static double myexp(double terms) {
double exponent = 1;
double result = 1;
double multiplier = 1;
for (double i = 1; i < terms; i++) {
multiplier = multiplier * exponent;
result += (multiplier / i);
}
return result;
}
public static double eToTheX(double exponent) {
double equals = Math.exp(exponent);
return equals;
}
}