|
|
@ -2,4 +2,18 @@ public class Calculations { |
|
|
|
public int calculateSquare(int num) { |
|
|
|
return (num * num); |
|
|
|
} |
|
|
|
|
|
|
|
public int calculateFactorial(int num) { |
|
|
|
if (num < 0) { |
|
|
|
throw new IllegalArgumentException("Factorial is not defined for negative numbers"); |
|
|
|
} |
|
|
|
if (num == 0 || num == 1) { |
|
|
|
return 1; // Factorial of 0 and 1 is 1 |
|
|
|
} |
|
|
|
int factorial = 1; |
|
|
|
for (int i = 2; i <= num; i++) { |
|
|
|
factorial *= i; |
|
|
|
} |
|
|
|
return factorial; |
|
|
|
} |
|
|
|
} |