title: Writing an isPrime function in java and using Math.sqrt
body: <p>When writing an isPrime function to return a  Boolean in Java, I have seen a lot of examples where people use Math.sqrt(number) in their for loop. Can someone explain why and what this function is doing in the for loop? I have attached an example for reference. Thanks!</p>
  
  <pre><code>    public boolean isPrime(int n) {
         if (n &lt;= 1) {
             return false;
         }
         for (int i = 2; i &lt; Math.sqrt(n); i++) {
             if (n % i == 0) {
                 return false;
             }
         }
         return true;
      }
  </code></pre>