This program consists of two functions in one class. It demonstrates a recursive function to calculate the factorial of a number.
Factorials
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);
}
}
dharween0629 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.