@@ -0,0 +1,1685 @@
+/****************************************************%0A *                 Birthday problem.%0A *%0A * Expected output:%0A * (percents could be slightly different)%0A *%0A * With 23 students, there is a 50.79%25 chance that%0A * at least 2 have the same birthday.%0A *%0A * With 70 students, there is a 99.91%25 chance that%0A * at least 2 have the same birthday.%0A ***************************************************/%0Apublic class Birthday %7B%0A%0A    /**%0A     * This method should do the following%0A     * --%3E create an array of size 'classSize'%0A     * --%3E fill the array with random numbers from 1 to 365%0A     * --%3E return 1 if two or more numbers in the array%0A     *     are the same else return 0%0A     */%0A    public static int makeClass(int classSize) %7B%0A%0A        // Array with random numbers from 1 to 365%0A        int%5B%5D c = new int%5BclassSize%5D;%0A        for (int i=0; i%3CclassSize; i++)%0A            c%5Bi%5D = (int) (Math.random() * 365) + 1;%0A%0A        for (int i=0; i%3Cc.length; i++) %7B%0A            for (int j=i+1; j%3Cc.length; j++) %7B%0A                if (c%5Bj%5D == c%5Bi%5D) return 1;%0A            %7D%0A        %7D%0A%0A        return 0;%0A    %7D%0A%0A    /**%0A     * This method calls the 'makeClass' method within%0A     * a for loop 1000 times.  It then prints out the%0A     * percent of times that at least 2 students have the%0A     * same birthday.%0A     */%0A    public static void callMakeClass(int classSize) %7B%0A%0A        int total = 0;%0A        for (int i=0; i%3C1000; i++) %7B%0A            total += makeClass(classSize);%0A        %7D%0A%0A        System.out.println(total / 1000.0 * 100);%0A%0A    %7D%0A%0A    /***%0A     * The main method is complete.%0A     */%0A    public static void main(String%5B%5D args) %7B%0A        callMakeClass(23);%0A        callMakeClass(70);%0A    %7D%0A%7D%0A

Add Birthday