/** * Java实现n的阶乘分别用递归和非递归 * * @author hjsjy * @create 2018/9/30 * @since 1.0.0 */ public class factorialtest { /** * 递归方法 * @param a * @return */ public static int testA(int n){ if(n==0) { return 1; }else{ int b=1; while(n>0){ b=b*n; n=n-1; } return b; } } /** * 非递归的方法 * @param b * @return */ public static int testB(int n){ if(n==0){//终止条件 return 1; } return n*testB(n-1);//递归 } }

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2021-06-05
  • 2021-12-07
  • 2021-08-28
猜你喜欢
  • 2021-11-08
  • 2021-12-06
  • 2021-11-17
  • 2021-08-07
  • 2021-11-17
相关资源
相似解决方案