mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
@@ -22,9 +22,7 @@ public class PiNilakantha {
|
||||
*/
|
||||
public static double calculatePi(int iterations) {
|
||||
if (iterations < 0 || iterations > 500) {
|
||||
throw new IllegalArgumentException(
|
||||
"Please input Integer Number between 0 and 500"
|
||||
);
|
||||
throw new IllegalArgumentException("Please input Integer Number between 0 and 500");
|
||||
}
|
||||
|
||||
double pi = 3;
|
||||
@@ -32,15 +30,9 @@ public class PiNilakantha {
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
if (i % 2 == 0) {
|
||||
pi =
|
||||
pi +
|
||||
4.0 /
|
||||
(divCounter * (divCounter + 1) * (divCounter + 2));
|
||||
pi = pi + 4.0 / (divCounter * (divCounter + 1) * (divCounter + 2));
|
||||
} else {
|
||||
pi =
|
||||
pi -
|
||||
4.0 /
|
||||
(divCounter * (divCounter + 1) * (divCounter + 2));
|
||||
pi = pi - 4.0 / (divCounter * (divCounter + 1) * (divCounter + 2));
|
||||
}
|
||||
|
||||
divCounter += 2;
|
||||
|
||||
Reference in New Issue
Block a user