if found a prime checker in java, which uses this method. Can somebody explain, why the for-loop goes to the square root of the searched prime number? - Is there a more efficient way of doing this? - Thank you!
    public static boolean isPrime(int p){ 
            if(p % 2 == 0 || p < 2){ 
                return false; 
            }  
            else {  
                System.out.println("Sqare: " + (int)Math.sqrt(p));
                for(int i = 3; i <= (int)Math.sqrt(p); i = i+2){ 
                    if(p % i == 0){  
                        return false; 
                    }
                }
            } 
            return true;  
}
 
    