Skip to content

Instantly share code, notes, and snippets.

@Ragnok123
Created December 24, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ragnok123/662d4c1dcc10c74e2dd0a3a112a53afe to your computer and use it in GitHub Desktop.
Save Ragnok123/662d4c1dcc10c74e2dd0a3a112a53afe to your computer and use it in GitHub Desktop.
PI
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