-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise05_25.java
More file actions
48 lines (41 loc) · 1.12 KB
/
Copy pathExercise05_25.java
File metadata and controls
48 lines (41 loc) · 1.12 KB
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
40
41
42
43
44
45
46
47
48
package Chapter5;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author jorda
*/
public class Exercise05_25 {
public static void main(String[] args){
double sum = 0;
double value = 10000.0;
for (double d = 1; d <= (2*value-1); d+=2) {
sum += 1 / d;
d += 2;
sum -= 1 /d;
}
double pi = 4 * sum;
System.out.println("PI value for i = 10000: " + pi);
sum = 0;
value = 20000.0;
for (double d = 1; d <= (2*value -1); d+=2) {
sum += 1 / d;
d += 2;
sum -= 1 /d;
}
pi = 4*sum;
System.out.println("PI value for i = 20000: " + pi);
sum = 0;
value = 100000.0;
for (double d = 1; d <= (2*value -1); d+=2) {
sum += 1 / d;
d += 2;
sum -= 1 /d;
}
pi = 4*sum;
System.out.println("PI value for i = 20000: " + pi);
}
}