提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
用于for语句以迭代方法计算阶乘。
public class Main// 来 自 nowjava - 时 代 Java { // recursive declaration of method factorial public static long factorial(long number) { long result = 1; // iterative declaration of method factorial for (long i = number; i >= 1; i--) result *= i; return result; } // output factorials for values 0-10 public static void main(String[] args) { // calculate the factorials of 0 through 10 for (int counter = 0; count