Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Geburtsparadoxon {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Wie viele Versuche? ");
- double t = scanner.nextDouble();
- System.out.print("Wie viele Personen? ");
- int n = scanner.nextInt();
- int[] a = new int[n];
- double gleich = 0;
- boolean check = false;
- for (double i = 0; i < t; i++) {
- for (int j = 0; j < a.length; j++) {
- a[j] = (int) (Math.random() * 364 + 1);
- }
- for (int k = 0; k < n; k++) {
- for (int l = 0; l < n; l++) {
- if (a[k] == a[l] && k != l) check = true;
- }
- }
- if (check) gleich++;
- check = false;
- }
- System.out.println("Wahrscheinlichkeit: " + (gleich / t * 1.0));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement