Java Add Two Numbers
Add two numbers with unlimited length values. Here number take as strings and splited into fixed length and then process addition.
In java if you take number then addition not possible with unlimited length value.
–  September 11th, 2018
public class StringAddition {       public static void main(String[] args) {           String a = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";         String b = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";         String sum = "";           System.out.println("--Addition--");         String c = sum(a.substring(a.length()-18), b.substring(b.length()-18), "0");         String d = sum(a.substring(a.length()-36, a.length()-18), b.substring(b.length()-36,b.length()-18), (c.length()>18?c.substring(0,1):"0"));         String e = sum(a.substring(a.length()-54, a.length()-36), b.substring(b.length()-54,b.length()-36), (d.length()>18?d.substring(0,1):"0"));         String f = sum(a.substring(a.length()-72, a.length()-54), b.substring(b.length()-72,b.length()-54), (e.length()>18?e.substring(0,1):"0"));         String g = sum(a.substring(a.length()-90, a.length()-72), b.substring(b.length()-90,b.length()-72), (f.length()>18?f.substring(0,1):"0"));           sum = (g.length()>18?g.substring(1):g) +          (f.length()>18?f.substring(1):f) +          (e.length()>18?e.substring(1):e) +          (d.length()>18?d.substring(1):d) +          (c.length()>18?c.substring(1):c) ;           System.out.println("--Result--");         System.out.println(sum);       }       static String sum(String a, String b, String carry) {           String res = String.valueOf(Long.parseLong(a) + Long.parseLong(b) + Integer.parseInt(carry));         System.out.println(a+" + "+b+" + "+carry+" = "+res);         return res;       }   }
Download Source Code