Java examples for java.lang:Math Number
Computes the factorial of a number.
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int number = 2; System.out.println(factorial(number)); }/*from ww w . j a va2s .c o m*/ /** * Computes the factorial of a number. * * @param number An integer whose factorial to compute. * @return The factorial of the integer. */ public static int factorial(int number) { if (number == 0) { return 1; } else { return number * factorial(number - 1); } } }