summaryrefslogtreecommitdiff
path: root/java/04-factorial/Factorial.java
blob: 0b2e650262807c45aca22a5b8693c0d8b8da1ad5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Factorial {
    public static void main(String[] args) {
        int x = factorial(5);

        System.out.println(x);

        int y = factorial(10);

        System.out.println(y);

        System.out.println(factorial(3));
    }

    public static int factorial(int x) {
        if (x == 0) {
            return 1;
        }

        return x * factorial(x - 1);
    }
}