Enter any integer of whch you want to find factorial as an input. Now we make a new method named fact which calls itself untill we get the final output.
Here is the source code of the Java Program to Find Factorial Value With Using Recursion. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Factorial
public static void main(String args)
int n, mul;
Scanner s = new Scanner(System.in);
System.out.print("Enter any integer:");
n = s.nextInt();
Factorial obj = new Factorial();
mul = obj.fact(n);
System.out.println("Factorial of "+n+" :"+mul);
int fact(int x)
if(x > 1)
return(x * fact(x - 1));
$ javac Factorial.java $ java Factorial Enter any integer:8 Factorial of 8 :40320
Sanfoundry Global Education & Learning Series – 1000 Java Programs.