title: Project Euler #10, java
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3045482/project-euler-problem-10-java-solution-not-working">Project Euler, Problem 10 java solution not working</a>  </p>
  </blockquote>
  
  
  
  <p>So, I'm attempting to solve <a href="http://projecteuler.net/index.php?section=problems&amp;id=10" rel="nofollow noreferrer">Project Euler Problem 10</a> in Java, and I'm getting not the right answer. Here's my code:</p>
  
  <pre><code>public class Problem10 {
  public static void main(String[] args)
  {
      long sum =0;
      for(int i =3;i&lt;2000000;i+=2)
      {
          if(isPrime(i))
          {
              sum+=i;
          }
      }
      System.out.println(sum);
  }
  
  public static boolean isPrime(int n)
  {
      boolean prime = true;
      if (n&lt;2) return false;
      if (n==2) return true;
      if (n%2==0) return false;
      for (int i = 3; i&lt;=Math.sqrt(n);i+=2)
      {
          if (n%i==0)
          {
              prime=false;
              break;
          }
      }
      return prime;
  }
  }
  </code></pre>
  
  <p>Which prints out 142913828920, which project Euler tells me is wrong.</p>
  
  <p>Any ideas?</p>
  
  <p>(Also, I know my method for finding primes is terribly inefficient.)</p>