我正在打印前 10 个数字的阶乘,所以它是 0 - 9。下面的代码对我有用。但是我无法使循环使 0 的阶乘也在循环内。任何建议表示赞赏。谢谢你。
public class fact {
public static void main(String[] args) {
System.out.println("\n\n(f) Loop to print first 10 factorial numbers");
System.out.println("\nFactorial of 0 is 1");
int fact = 1;
int index = 1;
while (index < 10)
{
fact*=index;
System.out.println("Factorial of " + index + " is " + fact);
index++;
}
}
}