package io.anand.play;

import java.util.Arrays;

public class StringNumberAddition {

    private static class CarryPlace {
        int carry = 0;
        int place = 1;
        int sum   = 0;
    }
    private static CarryPlace carryPlace = new CarryPlace();

    private static void addStringDigits (char digOne, char digTwo) {
        int val             = carryPlace.carry + (digOne - '0') + digTwo - '0';
        carryPlace.carry    = val / 10;
        carryPlace.sum     += (val % 10) * carryPlace.place;
        carryPlace.place   *= 10;
    }

    private static void addStringDigits (char digOne) {
        addStringDigits(digOne, '0');
    }

    private static void addStringDigits () {
        addStringDigits('0', '0');
    }

        // Start from the end of both strings and add them one place value
    // at a time, do account for carry
    private static int addStringNumbers (String numOne, String numTwo) {
        // Sanitize the inputs
        // Null strings, empty strings
        // non numeric characters in the input
        // define the expectation and return a defined output to indicate invalid input

        int len1    = numOne.length();
        int len2    = numTwo.length();
        // Determine the long string and make it as numOne
        // This helps rest of the logic to treat indices and
        // strings to pick for adding remaining digits from the longer
        // string
        // Add remaining digits from longer string
        if (len1 < len2) {
            String temp = numTwo;
            numTwo      = numOne;
            numOne      = temp;
            int    len  = len2;
            len2        = len1;
            len1        = len;
        }

        // Now numOne is the longer string and len1 is it's length
        // Need the diff to use the offset for loop on longer string
        int diff = len1 - len2;

        // Will traverse both till we finish the shorter string length
        for (int i = len2 - 1; i >= 0; i--)
            addStringDigits(numOne.charAt(i + diff), numTwo.charAt(i));

        // Remaining digits from longer number
        // not a big one here, but can refactor this logic to reduce duplication and errors
        for (int i = diff - 1; i >= 0; i--)
            addStringDigits(numOne.charAt(i));

        // Last addition would have possible left acarry and do not
        // ignore the place value for this carry and add it
        addStringDigits();
        return carryPlace.sum;
    }

    public static void main(String []args){
        String numOne = "900097894";
        String numTwo = "0050087";

        System.out.println("Input: number 1: " + numOne + ", number 2: " + numTwo);
        System.out.println("Sum: " + addStringNumbers(numOne, numTwo));
    }
}

@@ -136,16 +136,30 @@
 t carry 
+              
 = 0;%0A   
@@ -173,16 +173,30 @@
 t place 
+              
 = 1;%0A   
@@ -210,19 +210,88 @@
 t sum   
-= 0
+              = 0;%0A        StringBuilder sumString = new StringBuilder()
 ;%0A    %7D%0A
@@ -602,16 +602,82 @@
 .place;%0A
+        carryPlace.sumString.insert(0, (char)((val %25 10) + '0'));%0A
         
@@ -2600,24 +2600,91 @@
 ngDigits();%0A
+        System.out.println(%22Sum String: %22 + carryPlace.sumString);%0A
         retu

Build a string result as well