Skip to content

Instantly share code, notes, and snippets.

@AlexRomanofff
Created November 24, 2016 06:57
Show Gist options
  • Save AlexRomanofff/14d48787ee4d4df4ab2a2f7d2886e2c6 to your computer and use it in GitHub Desktop.
Save AlexRomanofff/14d48787ee4d4df4ab2a2f7d2886e2c6 to your computer and use it in GitHub Desktop.
package homework;
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("input number from 4 to 12");
int a = sc.nextInt();
if (a < 4 || a > 12) {
System.out.println("wrong input number!!!"); }
else {
System.out.println(calcFactorial(a));
}
}
public static long calcFactorial(int a) {
long fact=1;
for(int i=1; i<=a; i++) {
fact=fact*i;
}
return fact;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment