Java - Class calculate Factorial

Description

calculate Factorial

Demo

import java.util.Scanner;

public class Problem12 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        System.out.print(calculateFactorial(number));

    }//from w  w  w . j av a2s  .co m

    public static int calculateFactorial(int n) {

        if (n == 0) {
            return  1;

        } else {

            return n * calculateFactorial(n - 1);
        }
    }
}

Related Topic