title: What is a good way to implement choose notation in Java?
body: <p>... preferably in Java. Here is what I have:</p>
  
  <pre><code>//x choose y
  public static double choose(int x, int y) {
      if (y &lt; 0 || y &gt; x) return 0;
      if (y == 0 || y == x) return 1;
  
      double answer = 1;
      for (int i = x-y+1; i &lt;= x; i++) {
          answer = answer * i;
      }
      for (int j = y; j &gt; 1; j--) {
          answer = answer / j;
      }
      return answer;
  }
  </code></pre>
  
  <p>I'm wondering if there's a better way of doing this?</p>