0

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

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);
}
}

While pursuing a Computer Science degree, I founded DaniWeb.com, an online community for developers and IT professionals. I coded the backend platform from the ground up and I also do all of the advertising sales and SEO. I'm a super-geeky programmer with a passion for Internet marketing.

2
Contributors
1
Reply
3
Views
12 Years
Discussion Span
Last Post by dharween0629
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.