1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
photoshop1234 [79]
3 years ago
8

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.
Computers and Technology
1 answer:
poizon [28]3 years ago
4 0

Answer:

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;

   }

}

}

You might be interested in
There are 12 inches in a foot and 3 feet in a yard. Create a class named InchConversion. Its main() method accepts a value in in
Dafna1 [17]

Answer:

import java.util.Scanner;

public class InchConversion

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

   

 System.out.print("Enter inches: ");

 double inches = input.nextDouble();

 

 inchesToFeet(inches);

 inchesToYards(inches);

}

public static void inchesToFeet(double inches){

    double feet = inches / 12;

    System.out.println(inches + " inches = " + feet + " feet");

}

public static void inchesToYards(double inches){

    double yards = inches / 36;

    System.out.println(inches + " inches = " + yards + " yards");

}

}

Explanation:

In the inchesToFeet() method that takes one parameter, inches:

Convert the inches to feet using the conversion rate, divide inches by 12

Print the feet

In the inchesToYards() method that takes one parameter, inches:

Convert the inches to yards using the conversion rate, divide inches by 36

Print the yards

In the main:

Ask the user to enter the inches

Call the inchesToFeet() and inchesToYards() methods passing the inches as parameter for each method

7 0
2 years ago
Q1. Information systems that monitor the elementary activities and transactions of the organizations are: I a. Management-level
VashaNatasha [74]

Answer:

B. Operational-level systems monitor the elementary activities and transactions of the organization.

6 0
2 years ago
Discuss one simple example of hybrid computer.​
andrezito [222]

Answer:

thermometer , petrol pump

5 0
2 years ago
Computer engineering is a career that......
WITCHER [35]

Answer:

Computer engineering is a career that works on the development and research of new technology-related things.

Explanation:

4 0
2 years ago
What goes hand and hand with focus? A) company B) non-profit C) business D) organization
Katyanochek1 [597]

Answer:

I think the answer is D but please let me know if i am wrong

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • 1. What is the difference between a learner’s license and an operator’s license?
    10·1 answer
  • which is the quickest way to change the font color in multiple, randomly located cells in a worksheet?
    6·2 answers
  • Describe the components of the Web. Your friend wants to create and publish a Web page. He tells you that he wants to learn the
    9·1 answer
  • Which of these statements about the truck driving occupation in the U.S. are accurate?
    12·2 answers
  • Hey guys, I don’t have a problem for you but If anyone knows do you still pass your grade level if you failed 1 class in the las
    11·2 answers
  • Why is dark supereffective against ghost?
    5·2 answers
  • Laura is filming a scene in which the subject is sitting with a lit fireplace behind him. The only other source of light in the
    15·1 answer
  • You are setting up a home network for your friend. She has students visiting her home regularly for lessons and wants to provide
    14·1 answer
  • In numpy to append two arreys vertically the function __ is used
    12·2 answers
  • How to stop sharing location without them knowing imessage.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!