This repository has been archived on 2025-12-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2024-09-20 14:17:13 +03:00

30 lines
757 B
Java

import java.util.*;
public class Exercise2 {
static Scanner sc = new Scanner(System.in);
public static long factoNumber(int f) {
int count = 1;
long ans = 1;
while (count <= f) {
ans *= count;
count++;
}
return ans;
}
public static void main(String[] args) {
try {
System.out.print("");
int number = sc.nextInt();
if (number <= 0)
throw new Exception("Value must be positive integer");
else {
System.out.println("The factorial of " + number + " is " + factoNumber(number));
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}