title: Why does this code add 1 to the result?
body: <p>If <code>if (n > 0)</code> it returns a normal result, however <code>if (n >= 0)</code> it returns the normal result + 1, which I don't understand because 0 * 0 = 0. If anyone knows why this does this I would love to figure this out.</p>
  
  <pre><code>import java.util.*;
  
  // Recursive method returns sum of first n squares
  public class RecursiveSum
  {
      public static void main(String[] args)
      {
          while (true)
          {
              Scanner keyboard = new Scanner(System.in);
  
              System.out.println("Enter a number:\tIf you want to exit, enter a negative number.");
  
              int n = keyboard.nextInt();
  
              if (n &lt; 0)
                  System.exit(0);
  
              System.out.println("sum(" + n + ") = " + sum(n));
          }
      }
  
      public static int sum(int n)
      {
          int sum2 = n * n;
  
          if (n &gt;= 0)
              sum2 += sum(n - 1);
  
          return sum2;
      }
  }
  </code></pre>