|
@ -16,4 +16,22 @@ public class Calculations { |
|
|
} |
|
|
} |
|
|
return factorial; |
|
|
return factorial; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static boolean isPrime(int num) { |
|
|
|
|
|
if (num <= 1) { |
|
|
|
|
|
return false; // Numbers less than or equal to 1 are not prime |
|
|
|
|
|
} |
|
|
|
|
|
if (num == 2 || num == 3) { |
|
|
|
|
|
return true; // 2 and 3 are prime numbers |
|
|
|
|
|
} |
|
|
|
|
|
if (num % 2 == 0) { |
|
|
|
|
|
return false; // Even numbers greater than 2 are not prime |
|
|
|
|
|
} |
|
|
|
|
|
for (int i = 3; i <= Math.sqrt(num); i += 2) { |
|
|
|
|
|
if (num % i == 0) { |
|
|
|
|
|
return false; // If num is divisible by any number from 3 to sqrt(num), it's not prime |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; // If num is not divisible by any number from 2 to sqrt(num), it's prime |
|
|
|
|
|
} |
|
|
} |
|
|
} |