Java阶乘代码如下:
public class Factorial {
public static void main(String[] args) {
int n = 5; // 可以修改这个值来计算不同数字的阶乘
long factorial = 1;
for (int i = 1; i <= n; i++) {
factorial *= i;
}
System.out.println("阶乘结果为: " + factorial);
}
}