Add two Big Integer Values together in Java
Description
The following code shows how to add two Big Integer Values together.
Example
/*from ww w . j ava 2s . c o m*/
import java.math.BigInteger;
public class Main {
public static void main(String[] argv) throws Exception {
// Create via a string
BigInteger bi1 = new BigInteger("1234567890123456890");
System.out.println(bi1);
// Create via a long
BigInteger bi2 = BigInteger.valueOf(123L);
System.out.println(bi2);
bi1 = bi1.add(bi2);
System.out.println(bi1);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »