How to find the sum of two large numbers that cannot be stored in any primitive data type?
I assume that "any data type" means "any primitive data type."
Depending on the type of your data, you can use BigIntegeror BigDecimal.
BigInteger
BigDecimal
You can perform the calculation manually, saving 2 numbers as Strings(or an array char[]), and then doing the repetition with char-by- char.
Strings
char[]
char
import java.math.BigInteger; BigInteger n1 = new BigInteger("123456789012345678901234567890"); BigInteger n2 = new BigInteger("111122222233334445556666"); BigInteger result = n1.add(n2); System.out.println(result.toString());