📄 computefactorial.java
字号:
// ComputeFactorial.java: Compute factorial of an integer
public class ComputeFactorial
{
public static void main(String[] args)
{
// Prompt the user to enter an integer
System.out.println("Please enter a nonnegative integer");
int n = MyInput.readInt();
System.out.println("Factorial of " + n + " is " + factorial(n));
}
// Recursive method for computing factorial of n
static long factorial(int n)
{
if (n == 0) // Stopping condition
return 1;
else
return n*factorial(n-1); // Call factorial recursively
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -