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