Java program to find factorial of number using recursion


Program
import java.util.*; public class FactorialRecursion { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n = s.nextInt(); long f = fact(n); System.out.println("Factorial of " + n + " = " + f); } public static long fact(int n) { if (n >= 1) return n * fact(n - 1); else return 1; } }
Input
Output