title: How to calculate consecutive integers using a for loop method and a recursive method?
body: <p>I need to calculate the sum of consecutive integers in 1.) a for loop method and 2.) a recursive method. Both methods are static int methods that take in two int parameters (one is the starting int and the other is the number of ints that come after it). For example, if I were to input (3, 3), the output should be 18 because 3 is the starting number and the 3 ints after are 4, 5, &amp; 6. When you add those all up (3+4+5+6) you get 18. Both methods are doing this same math, except one is doing so with a for loop and the other is doing so recursively.</p>
  
  <p>The problem I'm having here is my for loop method doesn't sum up properly. When I input (3, 3) the output is 31. Furthermore, I'm not quite sure how to write the recursive method since my for loop method doesn't work. May I get some help with this?</p>
  
  <p>Also, no Arrays or ArrayLists. This code should be able to work without using those.</p>
  
  <pre><code>public static int consecSum(int startingNum, int numInts){
      for (int i = numInts; i&gt;0; i--){
          startingNum += (startingNum + 1);
      }
      return startingNum;
  }
  </code></pre>
  
  <pre><code>public static int recursSum(int startingNum, int numInts) {
      if (startingNum == 0) {
          return 0;
      } else if (numInts == 0) {
          return startingNum;
      }
      return startingNum + recursSum(startingNum + numInts, numInts - 1);
  }
  </code></pre>
  
  <pre><code>3 \\startingNum (theres more code not shown where I use a scanner object to input these)
  3 \\numInts
  31 \\for loop output
  \\The recursive method just prints an error message
  </code></pre>