title: OddSum Recursion exercise, dont know how to make the sum
body: <pre><code>public class OddSum {
  
      public static int oddSum(int n) {
  
          int totalSum;
  
          if (n % 2 != 0 &amp;&amp; n &gt; 0) {
              totalSum = totalSum + n;
              System.out.println(totalSum);
              return oddSum(n - 1);
              //System.out.println(totalSum);
              //return 1;
          } else {
              if (n == 0) {
                  System.out.println(totalSum);
                  return totalSum;
              } else {
                  return oddSum(n - 1);
              }
          }
      }
  
      public static void main(String[] args) {
          oddSum(13);
      }
  }
  </code></pre>
  
  <p>Im a bit confused, if I assign totalSum = 0 then it just resets to zero every time the recursive method runs, im trying to sum all the odd numbers, its in the think java book, public and private variables havent been introduced yet.</p>