Birthdays.java
public class Birthdays
{
public static void main(String[] args)
{
int D = Integer.parseInt(args[0]);
int T = Integer.parseInt(args[1]);
int people = 0;
for (int t = 0; t < T; t++)
{
boolean[] days = new boolean[D];
while (true)
{
people++;
int d = (int) (D *
Math.random());
if (days[d]) break;
days[d] = true;
}
}
double average = (double) people / T;
System.out.println("Average =
" + average);
}
}
No comments:
Post a Comment