Java Factorial factorial(int input)

Here you can find the source of factorial(int input)

Description

factorial

License

Open Source License

Declaration

public static int factorial(int input) 

Method Source Code

//package com.java2s;
/****************************************************
Statistics Online Computational Resource (SOCR)
http://www.StatisticsResource.org//from www.j ava 2 s.c o m
     
All SOCR programs, materials, tools and resources are developed by and freely disseminated to the entire community.
Users may revise, extend, redistribute, modify under the terms of the Lesser GNU General Public License
as published by the Open Source Initiative http://opensource.org/licenses/. All efforts should be made to develop and distribute
factually correct, useful, portable and extensible resource all available in all digital formats for free over the Internet.
     
SOCR resources are distributed in the hope that they will be useful, but without
any warranty; without any explicit, implicit or implied warranty for merchantability or
fitness for a particular purpose. See the GNU Lesser General Public License for
more details see http://opensource.org/licenses/lgpl-license.php.
     
http://www.SOCR.ucla.edu
http://wiki.stat.ucla.edu/socr
 It s Online, Therefore, It Exists! 
****************************************************/

public class Main {
    public static int factorial(int input) {
        int output;
        switch (input) {
        case 0: {
            output = 1;
            break;
        }
        case 1: {
            output = 1;
            break;
        }
        case 2: {
            output = 2;
            break;
        }
        case 3: {
            output = 6;
            break;
        }
        case 4: {
            output = 24;
            break;
        }
        case 5: {
            output = 120;
            break;
        }
        case 6: {
            output = 720;
            break;
        }
        case 7: {
            output = 5040;
            break;
        }
        case 8: {
            output = 40320;
            break;
        }
        case 9: {
            output = 362880;
            break;
        }
        case 10: {
            output = 3628800;
            break;
        }
        case 11: {
            output = 39916800;
            break;
        }
        case 12: {
            output = 479001600;
            break;
        }
        case 13: {
            output = 13 * 479001600;
            break;
        }
        case 14: {
            output = 14 * 13 * 479001600;
            break;
        }
        case 15: {
            output = 15 * 14 * 13 * 479001600;
            break;
        }
        case 16: {
            output = 16 * 15 * 14 * 13 * 479001600;
            break;
        }
        case 17: {
            output = 17 * 16 * 15 * 14 * 13 * 479001600;
            break;
        }

        default: {
            output = 0;
        }
        }
        return output;
    }
}

Related

  1. factorial(double n)
  2. factorial(final int a)
  3. factorial(final long value)
  4. factorial(int c)
  5. factorial(int i)
  6. factorial(int integer)
  7. factorial(int n)
  8. factorial(int n)
  9. factorial(int n)