正在加载图片...
阶乘什算示例(3) 8-6 ·递归算法 /兴* This class shows a recursive method to compute factorials.This method calls itself repeatedly based on the formula:n!=n*(n-1)! **/ public class Factorial3 public long factorial(int n){ if(n=1)return n;/递归头 else return n*factorial(n-1);/递归调用自己 Programming in Java JAVA8-6 Programming in Java • 递归算法 /** * This class shows a recursive method to compute factorials. This method * calls itself repeatedly based on the formula: n! = n*(n-1)! **/ public class Factorial3 { public long factorial(int n) { if (n == 1) return n; //递归头 else return n*factorial(n - 1); //递归调用自己 } } 阶乘计算示例(3)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有