Created
September 24, 2011 00:50
-
-
Save icarocamelo/1238793 to your computer and use it in GitHub Desktop.
Factorial: OO x OO (FP inspired)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Factorial { | |
public static long declarativeFactorial(int n){ | |
assert n > 0 : "Argument must be greaten than 0"; | |
if (n == 1) | |
return 1; | |
else | |
return n * declarativeFactorial(n-1); | |
} | |
public static long imperativeFactorial(int n){ | |
assert n > 0 : "Argument must be greaten than 0"; | |
long result = 1; | |
for (int i = 2; i<= n; i++) { | |
result *= i; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment