用Java程序编写实现求1!+2!+3!+..+20!
时间: 2024-02-06 12:02:07 浏览: 69
Eclipse+IDE开发Java+Web应用程序0[1].6
public class Factorial {
public static void main(String[] args) {
for (int i = 1; i <= 20; i++) {
System.out.println(i + "! = " + factorial(i));
}
}
public static long factorial(int n) {
long result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
}
阅读全文