title: transforming an iterative function to recursive in java
body: <p>i want to transform this function to recursive form could anyone help me thx
  that function is to solve this stuff</p>
  
  <pre><code>X=1+(1+2)*2+(1+2+3)*2^2+(1+2+3+4)*2^3+ . . . +(1+2+3+4+. . . +n)*2^(n-1) 
  </code></pre>
  
  <pre><code>public static int calcX(int n) {
          int x=1;
          int tmp;
          for(int i = 1 ; i &lt;= n-1;i++) {
              tmp=0;
              for(int j = 1 ; j &lt;= i + 1;j++) {
                  tmp+=j;
              }
              x+=tmp*Math.pow(2, i);
          }
          return x;
      }
  </code></pre>
  
  <p>my attempt im new to recursive stuff</p>
  
  <pre><code>public static int calcXrecu(int n,int tmp,int i,int j) {
          int x=1;
          if(i &lt;= n-1) {
              if(j &lt;= i) {
                  calcXrecu(n,tmp+j,i,j+1);
              }
              else {
                  x = (int) (tmp*Math.pow(2, i));
              }
          }
          else {
              x=1;
          }
              return x;
      }
  </code></pre>