title: Java - Recursion sum of number and how it work
body: <p>I am trying to write a recursive function that when I call with number 5 for example then the function will calculate the sum of all digits of five. 
  1 + 2 + 3 + 4 + 5 = 15</p>
  
  <p>The current code always returns 0, how can the amount each time the n? </p>
  
  <pre><code>public class t {
  public static void main(String[] args) {
  
      System.out.println(num(5));
  }
  
  public static int num(int n) {
  
      int sum = 0;
      sum += n;
      if (n == 0)
          return sum;
  
      return num(n - 1);
  
  }
  
  }
  </code></pre>
  
  <p>thank you.</p>