What's Here?
- Members: 107,398
- Replies: 408,808
- Topics: 62,094
- Snippets: 2,250
- Tutorials: 600
- Total Online: 1,192
- Members: 54
- Guests: 1,138
Who's Online?
|
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!
|
Finds N! where n is an integer (in this case).
|
Submitted By: KYA
|
|
|
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
/*
* KYA
* Function can be static or not, depends on situation
* 8-4-08
*/
public static int factorial(int number)
{
int n = number;
int f = 1;
// 0! and 1! = 1
for (int i = 2; i < n+1; i++)
{
f *= i;
}
return f;
}
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|