tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Jodd > Utils > How to calculate the factorial of a given number

How to calculate the factorial of a given number 

Jodd is an open-source java library with lot of reusable components and feature rich utilities. This requires the library jodd-3.3.2.jar to be in classpath. The following example shows how to get the factorial of a given number using MathUtil.factorial() API.

File Name  :  
com/bethecoder/tutorials/jodd/utils/FactorialTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jodd.utils;

import jodd.util.MathUtil;

public class FactorialTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    System.out.println(MathUtil.factorial(0));
    System.out.println(MathUtil.factorial(1));
    System.out.println(MathUtil.factorial(2));
    System.out.println(MathUtil.factorial(3));
    System.out.println(MathUtil.factorial(4));
    System.out.println(MathUtil.factorial(5));
    System.out.println(MathUtil.factorial(6));
    
  }

}
   

It gives the following output,
1
1
2
6
24
120
720



 
  


  
bl  br