fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static long factorial(int n) {
  5. if (n < 0) {
  6. return 0; // Factorial is not defined for negative numbers
  7. }
  8.  
  9. long result = 1;
  10. for (int i = 2; i <= n; i++) {
  11. result = result * i;
  12. }
  13. return result;
  14. }
  15.  
  16. public static void main(String[] args) {
  17. Scanner scanner = new Scanner(System.in);
  18.  
  19. int n = scanner.nextInt();
  20.  
  21. System.out.println(factorial(n));
  22.  
  23. scanner.close();
  24. }
  25. }
Success #stdin #stdout 0.18s 54540KB
stdin
15
stdout
1307674368000