title: Adding Two Elements in an Array (Java)
body: <p>I need to write a method that adds the two last elements of two arrays together and add the sum on another array. But if the two elements are more than 10, then I would need to carry that number to the next array. </p>
  
  <p>This program should be similar to what an odometer does.</p>
  
  <p>Here is my sample code.</p>
  
  <pre><code>int [] sum(int []number1, int []number2)
  {   
      int [] total;
      int carry = 0;
      for ( int k = numbers1 - 1; k &gt;= 0; k++)
      {
          sum = number1[k] + number2[k] + carry;
          carry = sum/10;
          total[k] = sum
      }
      return total;
  }
  </code></pre>
  
  <p>An example output would be:</p>
  
  <p><strong><em>0 1 2 3 4</em></strong> </p>
  
  <p>0 8 9 9 9</p>
  
  <p>4 5 7 0 3</p>
  
  <p>5 4 7 0 2</p>
  
  <p>So the top array is just a visual aid that tells where the position for the number is.
  The program is suppose to add the next two arrays together. i.e. 9 + 3 = 12
  Since 12 is above 9, it carries over the 10 to the next set of arrays, that is why the third array only has a 2 in its place, and that is why the next array is 9 + 0 = 0; because the 10 was carried over.</p>
  
  <p>I am not sure why my code won't work. I don't get the right numbers. Could anyone give any hints or solution to the problem?</p>
  
  <p>-Thanks</p>