package com.practices.interview.questions;
import java.util.Scanner;
class Calculation
{
public int fact(int n)
{
int result;
if(n==0){
return 1;
}
result = fact(n-1) * n;
return result;
}
}
public class RecursiveFactorial
{
public static void main(String args[])
{
Calculation obj = new Calculation();
System.out.print("Enter the number = ");
Scanner sc=new Scanner(System.in);
int a= sc.nextInt();
int x= obj.fact(a);
System.out.println("The factorial of the number is : " + x );
sc.close();
}
}
import java.util.Scanner;
class Calculation
{
public int fact(int n)
{
int result;
if(n==0){
return 1;
}
result = fact(n-1) * n;
return result;
}
}
public class RecursiveFactorial
{
public static void main(String args[])
{
Calculation obj = new Calculation();
System.out.print("Enter the number = ");
Scanner sc=new Scanner(System.in);
int a= sc.nextInt();
int x= obj.fact(a);
System.out.println("The factorial of the number is : " + x );
sc.close();
}
}
Comments