RosettaCodeData/Task/Factorial/Apex/factorial-1.apex
2016-12-05 23:44:36 +01:00

11 lines
228 B
Text

public static long fact(final Integer n) {
if (n < 0) {
System.debug('No negative numbers');
return 0;
}
long ans = 1;
for (Integer i = 1; i <= n; i++) {
ans *= i;
}
return ans;
}