Skip to content

Instantly share code, notes, and snippets.

@joeyv
Last active December 26, 2015 13:29
Show Gist options
  • Save joeyv/7158381 to your computer and use it in GitHub Desktop.
Save joeyv/7158381 to your computer and use it in GitHub Desktop.
Calculates factorial of a number
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
int total = 1;
int i, num;
Scanner scan = new Scanner(System.in);
num = scan.nextInt();
for( i = num; i >= 1; i-- ){
total *= i;
}
System.out.print (num + " factorial is: " + total);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment