You are on page 1of 1

import java.until.

scanner;
public class LinearRecursion {
public static int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
}

else {
return n* factorial(n - 1);
}
}

public static void main(String[] args) {


int n;
System.out.print("Enter a number to compute the factorial: ");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int x = factorial(n);

System.out.prinln("The factorial of" + " " + n + " " + "is" + " " + x +
".");
}

You might also like