Efficiently determining if a number is prime Is this the most efficient way to find if a number is prime? I can't think of a better way and it seems to run pretty quickly.

    public boolean primes(int num){
    for(int i = 2; i &lt; num; i++){
        if(num % i == 0){
            System.out.println(num + " is not prime");
            return false;
        }
    }
    System.out.println(num + " is prime");
   return true; 
}
A faster method would be to skip all even numbers and only try up to the square root of the number.

public static boolean isPrime(int num){
    if ( num &gt; 2 &amp;&amp; num%2 == 0 ) {
        System.out.println(num + " is not prime");
        return false;
    }
    int top = (int)Math.sqrt(num) + 1;
    for(int i = 3; i &lt; top; i+=2){
        if(num % i == 0){
            System.out.println(num + " is not prime");
            return false;
        }
    }
    System.out.println(num + " is prime");
    return true; 
}