Android examples for java.lang:Math
Compute the factorial of a value Use this method for small values.
//package com.java2s; public class Main { /**/* w w w.ja v a 2 s . c o m*/ * Compute the factorial of a value * Use this method for small values. For larger values, use <code>factorial2</code> * * @param n must be >= 0 * @return the factorial value * @see factorial2 */ public static long factorial(int n) { if (n <= 1) return 1; else return n * factorial(n - 1); } }