Ad

added a bigger prime number to test and fixed the bug that one was a prime, since it is not.

Code
Diff
  • public class Primes {
      public static boolean isAPrime(int number) {
        if(number > 1 && number == 2) return true; //1 is not a prime number by definition
        else {
          for(int i = 3; i*i < number; i +=2) {
            if (number % i == 0) return false;
          }
        }
        return true;
      }
    }
    • public class Primes {
    • public static boolean isAPrime(int number) {
    • if(number == 1 || number == 2) return true;
    • if(number > 1 && number == 2) return true; //1 is not a prime number by definition
    • else {
    • for(int i = 3; i*i < number; i +=2) {
    • if (number % i == 0) return false;
    • }
    • }
    • return true;
    • }
    • }