Last active
December 26, 2015 09:19
-
-
Save imryan/7128283 to your computer and use it in GitHub Desktop.
Calculates factorials of n. Possibly wrong.
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
| import java.util.*; | |
| public class Factorial { | |
| public static void main(String[] args) | |
| { | |
| // Declare variables | |
| Scanner sc = new Scanner(System.in); | |
| int n = 0, total = 1; | |
| // Get input for n | |
| n = sc.nextInt(); | |
| for (int i = n; i >= 1; i--) | |
| { | |
| total *= i; | |
| } | |
| System.out.println(n + "! = " + total); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay cool, thanks for the tip!