Find factorial of given number using recursion function in ja a
Answers
Answered by
0
import java.util.Scanner;
class FactorialDemo{
public static void main(String args[]){
//Scanner object for capturing the user input
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number:");
//Stored the entered value in variable
int num = scanner.nextInt();
//Called the user defined function fact
int factorial = fact(num);
System.out.println("Factorial of entered number is: "+factorial);
}
static int fact(int n)
{
int output;
if(n==1){
return 1;
}
output = fact(n-1)* n;
return output;
}
}
Similar questions
Math,
6 months ago
Biology,
6 months ago
Science,
6 months ago
Computer Science,
1 year ago
Hindi,
1 year ago