# 生日悖论问题（想出主意但无法产生预期的结果）

``````public class Main {
public static void main(String[] args) {
int n = Integer.parseInt(args[0]); // number of possible birthdates (365)
int trials = Integer.parseInt(args[1]); // number of trials I want to conduct
int people = 0;
int csum = 0; // cumulative sum
int probability = 0; // probability = csum / trials (decimal form)
int [] data = new int[trials];
for (int i = 0; i < trials; i++) {
boolean[] hasSameBirthday = new boolean[n];
while (true) { // find out after how many people enter room before birthday match
people ++;
int d = (int) (n * Math.random());
if (hasSameBirthday[d]) break;
hasSameBirthday[d] = true;
}
data[i] += people; // append people value into array
csum += people;
probability = csum / trials;
}
for (int i = 1; i < 24; i++) {
System.out.println(i + "\t" + data[i] + "\t" +  probability); // attempt to return values(shown in picture below)
}
}
``````

}

I want to find the sum of all the experiments taken before the x th person enters the roomI know that probability is csum / trials but I cant find csum after many tries...expected output