Factorials

Updated Dani 0 Tallied Votes 213 Views Share

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);
    }
}
dharween0629 0 Newbie Poster

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

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.