fork download
  1. public class PrimeChecker {
  2. // Method to check if a number is prime
  3. public static Boolean isPrime(Integer num) {
  4. // Check if the number is less than 2
  5. if (num < 2) {
  6. // Numbers less than 2 are not prime
  7. return false;
  8. }
  9. // Loop from 2 to the square root of the number
  10. for (Integer i = 2; i <= Math.sqrt(num); i++) {
  11. // If the number is divisible by i, it's not prime
  12. if (num % i == 0) {
  13. // Return false if a divisor is found
  14. return false;
  15. }
  16. }
  17. // If no divisors are found, the number is prime
  18. return true;
  19. }
  20. }
Success #stdin #stdout #stderr 0.02s 9016KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #PrimeChecker
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #PrimeChecker (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
stderr
./prog:2: parse error, expected '}'
./prog:20: Unterminated string, attempting recovery