Check prime in Haskell

--Check whether an integer is a prime or not
--Least Divisor 
leastDivisor::Integer->Integer->Integer
leastDivisor x y | mod y x == 0 = x 
                 | x^2 > y = y
                 | otherwise = leastDivisor (x+1) y  

--Check prime number
isPrime::Integer->Bool
isPrime y = leastDivisor 2 y == y

Check prime using recursion in Java

    public static boolean prime(int d, int n)
    {
        if(n == 2)
            return true;
        else if(n % d == 0)
            return false;
        else if(d*d <= n)
            return prime(d+1, n);
        else 
            return true;
    }

Check prime using iteration in Java

    public static boolean isPrimeLoop(int n)
    {
        if( n == 2)
            return true;
        for(int d=2; d*d <= n; d++)
        {
            if(n % d == 0)
                return false;
        }
        return true;
    }