Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double berechne_pi(int tropfenzahl) {
- double pi = 0;
- int innerhalb = 0;
- int gesamt = tropfenzahl;
- while (tropfenzahl > 0) { // generiere Tropfen und addiere je nach Zugehörigkeit
- double dotx = Math.random();
- double doty = Math.random();
- if (dotx*dotx + doty*doty <= 1) {
- // Punkt liegt innerhalb des Kreises
- innerhalb++;
- } else {
- // Punkt liegt außerhalb des Kreises
- }
- tropfenzahl--;
- }
- pi = 4*(double)innerhalb/gesamt;
- return pi;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement