Skip to content

Instantly share code, notes, and snippets.

@thmain
Created June 2, 2018 04:48
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 thmain/469886811d1d86a9214a6cc35c699783 to your computer and use it in GitHub Desktop.
Save thmain/469886811d1d86a9214a6cc35c699783 to your computer and use it in GitHub Desktop.
public class FactorialIterative {
public static int factorial(int num){
if(num==0)
return 1;
int result = 1;
for (int i = 2; i <=num ; i++) {
result *= i;
}
return result;
}
public static void main(String[] args) {
int num = 7;
int fact = factorial(num);
System.out.println("Factorial of a number: " + num + " is(Iterative): " + fact);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment