提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
长类型的递归阶乘方法。
public class Main {// 来自 N o w J a v a . c o m // recursive method factorial (assumes its parameter is >= 0 public static long factorial(long number) { if (number <= 1) // test for base case return 1; // base cases: 0! = 1 and 1! = 1 else // recursion step return number * factorial(number - 1); } // output factorials for values 0-21 public static void main(String[] args) { // calculate the factorials of 0 through 21 for (int counter = 0; co