Created
September 11, 2017 16:43
-
-
Save Heasummn/1f4f9b94f68f39876ad520ade0b0a4e2 to your computer and use it in GitHub Desktop.
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 int factorial(int n) | |
{ | |
int total = 1; | |
for(int i = 1; i < n; n++) | |
{ | |
total *= i; | |
} | |
return total; | |
} |
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 int factorial(int n) | |
{ | |
if(n == 0 || n == 1) | |
{ | |
return 1; | |
} | |
return factorial(n - 1) * n; | |
} |
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 int factorial(int n) | |
{ | |
return Intstream.rangeClosed(1, n).reduce(1, (a, b) -> a * b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment