-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExp09.java
More file actions
39 lines (35 loc) · 796 Bytes
/
Copy pathExp09.java
File metadata and controls
39 lines (35 loc) · 796 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
31
32
33
34
35
36
37
38
39
import myPackage.*;
import java.util.*;
class Exp09
{
Scanner sc = new Scanner(System.in);
static double calculateSeries()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of terms ");
int n = sc.nextInt();
double ans = 1;
int sign = -1;
System.out.println("Enter the value of x ");
double x = sc.nextInt();
x = 3.142 * x / 180;
for(int i = 2; i < 2 * n; i = i + 2)
{
ans = ans + sign * ( myMath.power(x, i) / myMath.fact(i) );
sign = -sign;
}
return ans;
}
public static void main(String[] args)
{
double ans = calculateSeries();
System.out.println("The answer is " + ans);
}
}
/* OUTPUT
*
*Enter the number of terms
5
Enter the value of x
45
The answer is 0.7070347926963395 */