Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
11
Task/Factorial/Apex/factorial-1.apex
Normal file
11
Task/Factorial/Apex/factorial-1.apex
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
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;
|
||||
}
|
||||
7
Task/Factorial/Apex/factorial-2.apex
Normal file
7
Task/Factorial/Apex/factorial-2.apex
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
public static long factRec(final Integer n) {
|
||||
if (n < 0){
|
||||
System.debug('No negative numbers');
|
||||
return 0;
|
||||
}
|
||||
return (n < 2) ? 1 : n * fact(n - 1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue