Firstly don't use double, use modulo arithmetic to check.
Secondly, you need to loop until the square root.
Thirdly, what about negative numbers?
Finally, If you have special cases for 0, 1, 2 and 3 then your loop can be shorted if you read
this[
^]
Luckily I'm bored today. The method is STATIC because it does not use any member variables. The special cases shorten the run time considerably for any reasonably large number; say greater than 437;
static boolean isPrime(long number)
{
if (number < 0)
{
return isPrime(-number);
}
if (number == 0 || number == 1)
{
return false;
}
if (number % 2 == 0 || number % 3 == 0)
{
return true;
}
for (long divisor = 5;
divisor <= number/divisor;
divisor = divisor + 6)
{
if ((number % divisor) == 0 || (number % (divisor + 2)) == 0 )
{
return false;
}
}
return true;
}