Java Recursion Program Practise 1 - Factorial
Java Program to find Factorial of given number using Recursion
import java.util.*;
class Main {
int fact(int n){
if(n==0)
return 1;
else{
return(n*fact(n-1));
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a;
System.out.println("Enter a number to get the factorial with the help of recursion");
a = in.nextInt();
Main ob = new Main();
System.out.println(ob.fact(a));
}
}
Comments
Post a Comment