Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class FactorialCalculator {
public static void main(String[] args) {
int number = 5; // Change this to the desired number
long factorial = calculateFactorial(number);
System.out.println("Factorial of " + number + " is " + factorial);
}

public static long calculateFactorial(int n) {
if (n < 0) {
throw new IllegalArgumentException("Input must be a non-negative integer");
}
if (n == 0) {
return 1;
}
return n * calculateFactorial(n - 1);
}
}