Ask Question

The birthday paradox says that the probability that two people in a room will have the same birthday is more than half, provided n, the number of people in the room, is more than 23. This property is not really a paradox, but many people find it surprising. Design a Java program that can test this paradox by a series of experiments on randomly generated birthdays, which test this paradox for n = 5, 10, 15, 20, ..., 100.

+1
Answers (1)
  1. 24 January, 02:20
    0
    The Java code is given below with appropriate comments for explanation

    Explanation:

    / / java code to contradict birth day paradox

    import java. util. Random;

    public class BirthDayParadox

    {

    public static void main (String[] args)

    {

    Random randNum = new Random ();

    int people = 5;

    int[] birth_Day = new int[365+1];

    / / setting up birthsdays

    for (int i = 0; i < birth_Day. length; i++)

    birth_Day[i] = i + 1;

    int iteration;

    / / varying number n

    while (people < = 100)

    {

    System. out. println ("Number of people: " + people);

    / / creating new birth day array

    int[] newbirth_Day = new int[people];

    int count = 0;

    iteration = 100000;

    while (iteration! = 0)

    {

    count = 0;

    for (int i = 0; i < newbirth_Day. length; i++)

    {

    / / generating random birth day

    int day = randNum. nextInt (365);

    newbirth_Day[i] = birth_Day[day];

    }

    / / check for same birthdays

    for (int i = 0; i < newbirth_Day. length; i++)

    {

    int bday = newbirth_Day[i];

    for (int j = i+1; j < newbirth_Day. length; j++)

    {

    if (bday = = newbirth_Day[j])

    {

    count++;

    break;

    }

    }

    }

    iteration = iteration - 1;

    }

    System. out. println ("Probability: " + count + "/" + 100000);

    System. out. println ();

    people + = 5;

    }

    }

    }
Know the Answer?
New Questions in Computers & Technology
The williams family just bought a new van. the cost of the van is $26,857.00. state sales tax is 6% on the cost of the van. in addition, there is $250 worth of document preparation fees that must be paid.
Answers (1)
Which nation was the aggressor in the action described here? the soviet union japan germany italy?
Answers (2)
Which is the collective noun: Journalists Society
Answers (2)
Of the sixth graders in a school, 4/5 (fraction) play at least one sport. Of those 2/3 (fraction) play on a team. What fraction of the sixth graders play a sport on a team?
Answers (1)
What were two effects of the Eighteenth Amendment and the Volstead Act? A. a decrease in the amount of illegal liquor and the number of homemade stills B. a decrease in both prostitution and murder C.
Answers (1)
Vector A makes equal angles with x, y and z axis. value of its components (in terms of magnitude of vector A will be?
Answers (1)
How do i solve 7 - (3-8) ^2
Answers (1)
1. Determine whether the graphs of the given equation are Parallel, perpendicular, or neither. y=-2x+3, 2x+y=7. A. Parallel B. Perpendicular C. Neither 2. Determine whether the statement is always, sometimes, or never true.
Answers (2)
What is the primary purpose of socialization?
Answers (2)
In recent year a letter to Europe from the United States cost $0.94 to mail. A letter mailed within United States cost $0.44. Nancy mailed 5 letters for $3.70 some to Europe and some to the United States. how many letters did she send to Europe
Answers (1)