Java Program to Find Factorial of a Number Using Recursion
Example: Factorial of a Number Using Recursion
public class Factorial {
public static void main(String[] args) {
int num = 6;
long factorial = multiplyNumbers(num);
System.out.println("Factorial of " + num + " = " + factorial);
}
public static long multiplyNumbers(int num)
{
if (num >= 1)
return num * multiplyNumbers(num - 1);
else
return 1;
}
}
When you run the program, the output will be:
Factorial of 6 = 720
0 comments:
Post a Comment