Code Snippets

  

Java Source Code


Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 107,398 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 1,192 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Factorial Finder

Finds N! where n is an integer (in this case).

Submitted By: KYA
Actions:
Rating:
Views: 26

Language: Java

Last Modified: August 8, 2008
Instructions: Implement when you need to find a factorial of a number 12 or lower. Based on variable limits, it will roll over on higher values. There are many ways to work around this--be warned!

Snippet


  1. /*
  2. * KYA
  3. * Function can be static or not, depends on situation
  4. * 8-4-08
  5. */
  6. public static int factorial(int number)
  7. {
  8.     int n = number;
  9.     int f = 1;
  10.     // 0! and 1! = 1
  11.     for (int i = 2; i < n+1; i++)
  12.     {
  13.         f *= i;
  14.     }
  15.     return f;
  16. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month