A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a method that checks if a number is a prime number
Q:

Write a method that checks if a number is a prime number

0

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Write a method that checks if a number is a prime number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public Boolean isPrime(Integer n) {
boolean isPrime = true;
 for (int i = n - 1; i > 1; i--) {
     if (n % i == 0) {
         isPrime = false;
         break;
     }
 }
 return isPrime;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now