Created
December 24, 2019 15:39
-
-
Save Ragnok123/662d4c1dcc10c74e2dd0a3a112a53afe to your computer and use it in GitHub Desktop.
PI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class Main{ | |
public static double PI = 3; //it is aproximally value | |
public static void main (String[] args) throws java.lang.Exception{ | |
int n = 2; | |
for (int i = 0; i < 500; i++) { | |
PI += (i % 2 == 0 ? 1 : -1) * 4.0 / (n * (n + 1) * (n + 2)); | |
n += 2; | |
} | |
System.out.println(PI); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment