Java examples for java.lang:Math Algorithm
Calculate the factorial of n Pre: 0 <= n <= 12
//package com.java2s; public class Main { /**//w w w.j a v a2 s . c o m * Calculate the factorial of n * Pre: 0 <= n <= 12 * @param n The integer whose factorial is being computed * @return n! */ public static int factorial(int n) { int result = 1; while (n > 0) { result *= n--; } return result; } }