Skip to content

Instantly share code, notes, and snippets.

@Heasummn
Created September 11, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Heasummn/1f4f9b94f68f39876ad520ade0b0a4e2 to your computer and use it in GitHub Desktop.
Save Heasummn/1f4f9b94f68f39876ad520ade0b0a4e2 to your computer and use it in GitHub Desktop.
public int factorial(int n)
{
int total = 1;
for(int i = 1; i < n; n++)
{
total *= i;
}
return total;
}
public int factorial(int n)
{
if(n == 0 || n == 1)
{
return 1;
}
return factorial(n - 1) * n;
}
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