Array of Random Birthdays

时间:2017-04-10 03:14:15

标签: java arrays

After processing all of the N people, iterate over your array to compute: For each month, the fraction (or percentage) of people born in that month. The average of the 12 values you computed for the above. For each day, the fraction (or percentage) of people born on that day, whether in the same or in a different month. The average of the 31 values you computed for the above. The fraction (or percentage) of people born on exactly the same day.

public static void main(String[] args) {

    ArgsProcessor ap = new ArgsProcessor(args);
    int N = ap.nextInt("Number of people?");
    int [][] birthday = new int[12][31];


    for (int i=0; i<N; i++){
        int month = (int)(Math.random()*12);
        int day = (int)(Math.random()*31); 
        birthday[month][day] = birthday[month][day] + 1;  
    }

0 个答案:

没有答案