This program consists of two functions in one class. It demonstrates a recursive function to calculate the factorial of a number.

52 Views
package factorials;
public class Factorials
{
public static void main(String args[])
{
int y = 5;
System.out.print("\n\t" + y + " factorial = " + getFactorial(y) + "\n");
}
public static double getFactorial(int inum)
{
if (inum == 0) return 1;
else return inum * getFactorial(inum - 1);
}
}
About the Author

I recently moved from Long Island, NY to Palo Alto, CA, and I'm looking to meet fellow entrepreneurs here in Silicon Valley. Especially other technical founders!

what if i want to make factorial of user inputs? how to do it?