title: Perfect numbers. Something wrong
body: <p>I am trying to accomplish a task. To print 4 <a href="http://en.wikipedia.org/wiki/Perfect_number" rel="nofollow">perfect numbers</a> which are between 1 and 10000.</p>
  
  <blockquote>
    <p>In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself.</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>public class PerfectNumbers
  {
      public static void main(String[] args)
      {
          // Perfect numbers!
  
          for (int number = 1; number &lt; 10000; number++)
          {
              int sum = 0;
              int i = 1;
              while (i &lt; number)
              {
  
                  if (number % i == 0)
                  {
                      sum += i;
                      i++;
  
                  }
                  else
                  {   
                      i++;
                      continue;
                  }
  
                  if (sum == number)
                  {
                      System.out.println(number);
                  }
                  else
                  {
                      continue;
                  }
  
              }
          }
      }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>6
  24 &lt;--- This one is wrong because next must be 28. 
  28
  496
  2016
  8128
  8190
  </code></pre>
  
  <p>What is wrong in my code? Thank you.</p>