public static void main(String[] args) {
int n = factorial(30);
int x = 0;
while (x <= 30) {
System.out.println(x + " " + n);
x = x + 1;
}
public static int factorial (int n) {
if (n == 0) {
return 1;
} else {
return n * factorial (n-1);
}
}
}
我正在尝试打印出这样的东西:
0 1
1 1
2 2
3 6
4 24
...etc, up to 30 (30!)
我得到的是这样的:
0 (30!)
1 (30!)
...etc, up to 30
换句话说,我能够创建从0到30的左列,但我想让它在右栏中打印数字的阶乘.使用我的代码,它只在右侧列中打印30的阶乘.我希望它按照相应的数字旁边的顺序打印阶乘.如何修复我的代码来执行此操作?