A simple modulus based algorithm used in Java to find if the passed number is prime or not.
private boolean IsPrime(int i)
{
if (i <= 1) return false;
if (i == 2) return true;
if (i % 2 == 0) return false;
int n = (int)Math.round(Math.sqrt(i));
for (int x = 3; x <= n; x += 2)
{
// If it divides, it's not a prime
if (i % x == 0)
{
return false;
}
}
// If we got to this point, the number is prime
return true;
}