RosettaCodeData/Task/Factorial/Apex/factorial-1.apex
2023-07-01 13:44:08 -04: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;
}