-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ch3Ex7.java
39 lines (37 loc) · 833 Bytes
/
Ch3Ex7.java
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
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
public class Ch3Ex7
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter x input");
double x = input.nextDouble();
series(x);
input.close();
}
static void series(double x)
{
double fact =1;
double sum = 1;
for(int i = 1; i <=100; i++)
{
fact *=i;
sum += Math.pow(x, i)/fact;
if (i==1)
{
System.out.printf("When n is 1, sum =%.2f", sum);
System.out.println();
}
else if (i==10)
{
System.out.printf("When n is 10, sum =%.2f", sum);
System.out.println();
}
else if (i==50)
{
System.out.printf("When n is 50, sum =%.2f", sum);
System.out.println();
}
}
}
}