Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param n - max is 20
- * @return The factorial of the number
- */
- public static long stackFactorial(int n) {
- if (n == 1 || n == 0)
- return 1;
- else
- return stackFactorial(n - 1) * n;
- }
- /**
- * @param n - max is 20
- * @return The factorial of the number
- */
- public static long loopFactorial(int n) {
- long r = 1;
- for (long i = 1; i <= n; i++) {
- r *= i;
- }
- return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement