用Java写一个1阶乘到20阶乘的代码
时间: 2024-05-24 10:10:53 浏览: 102
java中的1到20的阶乘
5星 · 资源好评率100%
public class Factorial {
public static void main(String[] args) {
for (int i = 1; i <= 20; i++) {
long factorial = 1;
for (int j = 1; j <= i; j++) {
factorial *= j;
}
System.out.println(i + "! = " + factorial);
}
}
}
阅读全文