title: Java: How to sum the elements of two arrays with different lengths
body: <p>I am trying to add the elements of two arrays with different lengths together.
  The code below is only for the same length and here is all I have so far. </p>
  
  <pre><code>    //for the same lengths
  int[]num1 = {1,9,9,9};
  int[]num2 = {7,9,9,9};// {9,9,9}
  
      int total = 0, carry = 1;
      int capacity = Math.max(num1.length,num2.length);
      int []arraySum = new int [capacity];
  
          for (int i = capacity - 1 ; i &gt;= 0; i--)
          {   
              arraySum[i] = num1[i]+ num2[i];
  
              if (arraySum[i] &gt; 9)
              {
                  arraySum[i] = arraySum[i] % 10;
  
                  num2[i-1] = num2[i-1] + carry;  
              }
  
  
          }
  
      for(int i = 0; i &lt; arraySum.length; i++)
      {
          System.out.print(arraySum[i]);
      }
  </code></pre>
  
  <p>What should I do if I change the elements in num2 and length to like {9,9,9}?
  I know I probably need to put another for-loop as an inside for-loop and control the indices of the array with smaller length but how....?? One more thing... what should I do for those for-loops conditions because num1 and num2 will be eventually INPUTED by the user.</p>
  
  <p>Well, you can tell that the inputs are limited because if num1[0] + num2[0] > 9 the carry has no index to be placed, then it can't be compiled. So, I need to shift the whole array to the right and place the carry from num1[0] + num2[0]. Here is the problem!! Where should I put the shifting code? I am kinda confused.......</p>