Skip to content

Instantly share code, notes, and snippets.

@jsbonso
Last active January 16, 2021 22:14
Show Gist options
  • Save jsbonso/e3d3559e843ff35e86ff6aef75161e3d to your computer and use it in GitHub Desktop.
Save jsbonso/e3d3559e843ff35e86ff6aef75161e3d to your computer and use it in GitHub Desktop.
Factorial Code Example
/*
* Factorial
*
* 1. Get all factors (1, 2, 3 ... n) of a given number (n).
*. 2. Multiply all factors to get the value of the Factorial.
*
* Example:
*
* Factorial of 5:
* !5 = ?
* !5 = 5 * 4 * 3 * 2 * 1
* !5 = 120
*
*/
int input = 5;
int temp = 1;
for (int i=1; i <= input; i++){
temp = temp * i;
}
System.out.println("Factorial Result: " + temp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment