Addition of two very long integers
<p>For practice, I am trying to add two very long integers by placing them in arrays and adding the corresponding elements in the arrays. However, when trying to add the carry over, I'm having problems (I.e., the carry over is the 1, that for instance, you add to the tens place when you do 199 + 199 = 398).</p>

<p>When doing 167 + 189 I get the right answer which is 356. However, for this very example though (199 + 199), I'm getting 288 instead of 398. My question is, why do I get an incorrect answer when I do 199 + 199, if the carry over works well when I do 167 + 189?</p>

<pre><code>if (stringNumOneLength == stringNumTwoLength)
    {   int answer; 
        int carryOver = 0;
        int answerArray[] = new int[stringNumOneLength + 1];
        for (int i = 1; i &lt;= stringNumTwoLength; i = i + 1)
        {            
            answer = Character.getNumericValue(stringNumOne.charAt(stringNumOneLength - i)) + Character.getNumericValue(stringNumTwo.charAt(stringNumTwoLength - i) + carryOver);
            System.out.println(answer);
            if (answer &gt;= 10)
            {
                for (int j = 0; j &lt;= 9; j = j + 1)
                {
                    if (10 + j == answer) 
                    {
                        carryOver = 1;
                        answer = j;
                        System.out.println("The carryover is " + carryOver + ".");
                    }
                }
            }
            else
            {
                carryOver = 0;
            }

            answerArray[stringNumOneLength + 1 - i] = answer;
        }
        System.out.println(Arrays.toString(answerArray));
    }
</code></pre>

<p>The output is the following:</p>

<p>[1, 9, 9]</p>

<p>[1, 9, 9]</p>

<p>18</p>

<p>The carryover is 1.</p>

<p>8</p>

<p>2</p>

<p>[0, 2, 8, 8]</p>
