正在加载图片...
阶乘什算示例(2) 8-5 ·改进 public class Factorial2{ //create an array to cache values 0!Through 20! Static long[]table new long[21]; Static {table[0]1;} //factorial of 0 is 1 //Remember the highest initialized value in the array static int last 0; public static long factorial(int x){ while (last x){ table [last 1]table[last]*(last 1); last++; Programming in Java JAVA8-5 Programming in Java public class Factorial2 { //create an array to cache values 0! Through 20! Static long[] table = new long[21]; Static {table[0] = 1;} //factorial of 0 is 1 //Remember the highest initialized value in the array static int last = 0; public static long factorial(int x) { while (last < x) { table [last + 1] = table[last]*(last + 1); last++; } } 阶乘计算示例(2) • 改进
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有