title: Java Code for Project Euler #12
body: <p>I'm working on Problem #12 for Project Euler, which goes as follows:</p>
  
  <blockquote>
    <p>The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:</p>
    
    <p>1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...</p>
    
    <p>Let us list the factors of the first seven triangle numbers:</p>
    
    <p>1: 1</p>
    
    <p>3: 1,3</p>
    
    <p>6: 1,2,3,6</p>
    
    <p>10: 1,2,5,10</p>
    
    <p>15: 1,3,5,15</p>
    
    <p>21: 1,3,7,21</p>
    
    <p>28: 1,2,4,7,14,28</p>
    
    <p>We can see that 28 is the first triangle number to have over five divisors.</p>
    
    <p>What is the value of the first triangle number to have over five hundred divisors?</p>
  </blockquote>
  
  <p>This is the code I have so far, but the console does not return anything when it runs:</p>
  
  <pre><code>public class Euler12 {
      public static void main (String[] args) {
          int i = 1;
          int x = 2;
          boolean found = false;
          while (!found) {
              if (divisors(i) &gt; 500) {
                  System.out.println(i);
                  found = true;
              }
              else {
                  i +=x;
                  x++;
              }
          }
      }
  
      public static int divisors (int n) {
          int counter = 0;
          for (int i = 1; i &lt;= n; i++) {
              if (n % i == 0) counter++;
          }
          return counter;
      }
  }
  </code></pre>