factorial calculation for long value - Java java.lang

Java examples for java.lang:long

Description

factorial calculation for long value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        long number = 2;
        System.out.println(factorial(number));
    }// w  w  w .  jav  a  2  s .c  o  m

    public static long factorial(long number) {
        if (number <= 1)
            return 1;
        if (number == 2)
            return 2;
        return number * factorial(number - 1);
    }
}

Related Tutorials