package com.taoge.test; public class Test { /* * 计算 阶乘 * */ public static int jiecheng(int n){ if (n<0) { return 0; } if(n==1){ return 1; }else{ return n*jiecheng(n-1); } } /* * 计算排列 A(m,n) m在上,n在下 假设 n=6 ,m=4 即6*5*4*3 * @return 数学公式A(m,n) 的值 */ public static int paiLie(int n,int m){ if (n<m) { return 0; } int total=1; for (int i = 0; i < m; i++) { total=total*n; n--; } return total; } /** * 计算排列 C(m,n) m在上,n在下 假设 n=6 ,m=4 即A(6,4)/4! * C(n,m)=A(n,m)/m! * @returnC(n,m)的值
*/ public static int zuHe(int n,int m){ return paiLie(n,m)/jiecheng(m); } public static void main(String args[]){ //求出双色球一共有多少注 int redBallNum = zuHe(33, 6); int blueBallNum = zuHe(16, 1); int seleCuont = redBallNum* blueBallNum; System.out.println("双色球一共有:"+seleCuont+"注"); System.out.println("购买所有的需要注数需要人民币:"+seleCuont*2+"元"); } }