-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumbino.java
More file actions
30 lines (25 loc) · 745 Bytes
/
Numbino.java
File metadata and controls
30 lines (25 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
public class Numbino {
public static int factorial(int n) {
if (n == 0) {
return 1;
}
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
public static int bincoeff(int n, int r) {
if (r > n || r < 0) {
return 0; // Binomial coefficient is not defined for these values
}
int fact_n = factorial(n);
int fact_r = factorial(r);
int fact_nmr = factorial(n - r);
return fact_n / (fact_r * fact_nmr);
}
public static void main(String[] args) {
System.out.println(bincoeff(5, 2)); // Output should be 10
}
}