title: java: Birthday probability program
body: <p>I'm trying to create a program that finds the probability of two random students in a room to have the same birthday. Number of students and number of simulations is inputted. Whenever I run it though, with 23 students, I consistently get 0.69, which is inconsistent with the actual answer of about 0.50. I think it probbaly has something to do with the fact that, if there are 3 students with the same birthday, it will count it as 3 matches. But I'm not sure how to fix this problem and I've already tried multiple times. Can I get some help?</p>
  
  <pre><code>import java.util.Scanner;
  
  public class bday{
  public static void main(String[] args){
      Scanner inp = new Scanner(System.in);
      System.out.println("How many students?");
      int num = inp.nextInt();
      System.out.println("How many times?");
      int times = inp.nextInt();
      double x[] = new double[num];
      int match = 0;
      for(int i=0;i&lt;times;i++){
          for(int j=0;j&lt;num;j++){
              x[j] = (int)(Math.random()*365)+1;
          }
          for(int j=0;j&lt;num;j++){
              for(int k=j+1;k&lt;num;k++){
                  if(x[j]==x[k]){
                      match++;
                  }
              }
          }
      }
      double prob = (double)match/times;
      System.out.println("The probability for two students to share a birthday is "+prob+".");
  }}
  </code></pre>