Friday, 24 February 2012

Factorial

  1. public class NumberFactorial {
  2.  
  3.         public static void main(String[] args) {
  4.                
  5.                 int number = 5;
  6.                int factorial = number;      

  7.                 for(int i =(number - 1); i > 1; i--)
  8.                 {
  9.                         factorial = factorial * i;
  10.                 }
  11.        
  12.                 System.out.println("Factorial of a number is " + factorial);
  13.         }
  14. }

No comments: