Skip to content

Instantly share code, notes, and snippets.

@mmathys
Created October 15, 2020 16:00
Show Gist options
  • Save mmathys/8715e8521d38311700b6096bf3ffd17e to your computer and use it in GitHub Desktop.
Save mmathys/8715e8521d38311700b6096bf3ffd17e to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) throws Exception {
boolean plus = true;
double summe = 0;
for (int nenner = 1; nenner < 1000; nenner += 2) {
double bruch = 1.0 / nenner;
if (plus) {
summe += bruch;
} else {
summe -= bruch;
}
plus = !plus;
}
Out.println("pi ~ " + summe * 4);
}
}
public class Main {
public static void main(String[] args) throws Exception {
double zähler = 1;
double nenner = 1;
double summe = 1;
for (int i = 1; i < 100; i++) {
zähler *= i;
nenner *= 2 * i + 1;
summe += zähler / nenner;
}
Out.println("pi ~ " + summe * 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment