title: Output for adding very Large numbers does not come as expected
body: <p>Given two numbers as input, return the sum of the numbers. Note that the numbers can be very large and hence are provided as Strings.</p>
  
  <p>Note: Without using BigInteger class I have to add them.</p>
  
  <pre><code>#Sample Input #1
  
  add("2354725234782357","9999999999999999999999999988888888888")
  
  #Sample Output #1
  
  10000000000000000000002354714123671245
  
  #Sample Input #2
  
  add("1600","213")
  
  #Sample Output #2
  
  1813
  </code></pre>
  
  <p><strong>MyApproach</strong></p>
  
  <p>Since the numbers are very large on which I am not getting output.Can anyone guide what I am doing wrong and How to add these numbers.</p>
  
  <p><strong>Original code:</strong></p>
  
  <pre><code>public String add(String str1, String str2) {
      long number1 = Long.parseLong(str1);
      long number2 = Long.parseLong(str2);
      number1 = number1 + number2;
      return "" + number1;
  }
  </code></pre>
  
  <p>Parameters:</p>
  
  <pre class="lang-none prettyprint-override"><code>'2354725234782357' '9999999999999999999999999988888888888'  
  </code></pre>
  
  <p>Actual output:</p>
  
  <pre class="lang-none prettyprint-override"><code>null
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre class="lang-none prettyprint-override"><code>10000000000000000000002354714123671245
  </code></pre>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>As per MC Emperor suggestions, I got to know how to add numbers very large without using Any BigInteger.</p>
  
  <pre><code>Below is the code.
  
  public String add(String a, String b) 
  {
  
       String result = "";
      if(a.length()&gt;b.length())
      {
          int p=a.length()-b.length();
          for(int i=0;i&lt;p;i++)
           {
            b="0"+b;
           } 
      }
      if(b.length()&gt;a.length())
      {
          int p=b.length()-a.length();
          for(int i=0;i&lt;p;i++)
           {
             a="0"+a;
           } 
      }
      if(a.length()==b.length()) 
      {    
  
  
         int carry = 0;
        for (int i = a.length() - 1; i &gt;= 0; i--) 
        {
  
           int digitA = a.charAt(i) - 48;
           int digitB = b.charAt(i) - 48;
  
  
           int resultingNumber = digitA + digitB + carry;
           if (resultingNumber &gt;= 10) 
           {
  
              result = (resultingNumber % 10) + result;
               carry = 1;
           }
           else
          {
           result = resultingNumber + result;
           carry = 0;
          }
        }
        if (carry &gt; 0)
       {
         result = carry + result;
       }
  
     }
     return result;
   }
  }    
  </code></pre>