Professional Documents
Culture Documents
Factorial Recursion
Factorial Recursion
*;
class Factorial {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int result = factorial(n);
System.out.println(result);
}
// // - Get to a point where you can explain your approach to a 10 year old
// // - Take a stab at the high level logic & write it down.
// long factorial(int n) {
// // Base case
// // if n == 1, then we have to return.
// // Recursion
// long factorialOutput = n * factorial(n-1);
// return factorialOutput;
// }
// - Try to offload processing to functions & keeping your main code small.
// Milestone 4: Prove to the interviewer that your code works with unit tests
// - Make sure you check boundary conditions