Evaluate binomial coefficients: Difference between revisions

Undo revision 121504 by 210.212.240.147 (talk) No explanation of removal, use {{incorrect}} for incorrect examples
(Undo revision 121504 by 210.212.240.147 (talk) No explanation of removal, use {{incorrect}} for incorrect examples)
Line 491:
<lang j> 3 ! 5
10</lang>
 
=={{header|Java}}==
<lang java>public class Binom {
 
static long combinations(int n, int k) {
long coeff = 1;
for (int i = n - k + 1; i <= n; i++) {
coeff *= i;
}
for (int i = 1; i <= k; i++) {
coeff /= i;
}
return coeff;
}
 
public static void main(String[] args){
System.out.println(combinations(5, 3));
}
}</lang>
Output:
<pre>10.0</pre>
{{trans|Python}}
<lang java>public class Binom {
public static double binomCoeff(double n, double k) {
double result = 1;
for (int i = 1; i < k + 1; i++) {
result *= (n - i + 1) / i;
}
return result;
}
 
public static void main(String[] args) {
System.out.println(binomCoeff(5, 3));
}
}
</lang>
Output:
<pre>10.0</pre>
 
=={{header|JavaScript}}==
Anonymous user