Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active December 26, 2015 09:19
Show Gist options
  • Select an option

  • Save imryan/7128283 to your computer and use it in GitHub Desktop.

Select an option

Save imryan/7128283 to your computer and use it in GitHub Desktop.
Calculates factorials of n. Possibly wrong.
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);
}
}
@imryan
Copy link
Author

imryan commented Oct 24, 2013

Okay cool, thanks for the tip!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment