Calculate N Factorial - Java Algorithm

Java examples for Algorithm:Number

Description

Calculate N Factorial

Demo Code

import java.util.Scanner;

public class CalculateNFactorial {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int number = scn.nextInt();
        System.out.println(calculateFactorial(number));

    }//from w w w. ja  v  a  2 s.  com
    public static int calculateFactorial(int n){
        if(n == 0 || n == 1){
            return 1;
        } else {
            return n * calculateFactorial(n-1);
        }
    }
}

Related Tutorials