Advertisement
Asphorm

Untitled

May 10th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Geburtsparadoxon {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. System.out.print("Wie viele Versuche? ");
  9. double t = scanner.nextDouble();
  10. System.out.print("Wie viele Personen? ");
  11. int n = scanner.nextInt();
  12.  
  13. int[] a = new int[n];
  14. double gleich = 0;
  15. boolean check = false;
  16.  
  17. for (double i = 0; i < t; i++) {
  18. for (int j = 0; j < a.length; j++) {
  19. a[j] = (int) (Math.random() * 364 + 1);
  20. }
  21. for (int k = 0; k < n; k++) {
  22. for (int l = 0; l < n; l++) {
  23. if (a[k] == a[l] && k != l) check = true;
  24. }
  25. }
  26. if (check) gleich++;
  27. check = false;
  28. }
  29. System.out.println("Wahrscheinlichkeit: " + (gleich / t * 1.0));
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement