设计一个方法Combination(),给定两个非负整数m, n(m>n),计算C_n^m的值 例:C_3^5=(5×4×3)/(3×2×1) public class CombinationDemo { public static void main(String[] args) { System.out.println(Combination(6, 4)); //输出:15 System.out.println(Combination(10, 6)); //输出:210 } public static long Combination(int m, int n){ //补充方法代码 }}
时间: 2023-12-06 20:42:13 浏览: 70
Java for combinatorial number algorithm.zip_4MJN_M?n_enterbl4_组合
public static long Combination(int m, int n){
long result = 1;
for(int i=1; i<=n; i++){
result = result * (m-i+1) / i;
}
return result;
}
阅读全文