Java examples for Language Basics:BigInteger
Operating with Big Integer Values
import java.math.BigInteger; public class Main { public static void main(String[] args) { // Create via a string BigInteger bi1 = new BigInteger("1234567890123456890"); System.out.println(bi1);//w w w. j a v a2 s . co m // Create via a long BigInteger bi2 = BigInteger.valueOf(123L); System.out.println(bi2); bi1 = bi1.add(bi2); System.out.println(bi1); bi1 = bi1.multiply(bi2); System.out.println(bi1); bi1 = bi1.subtract(bi2); System.out.println(bi1); bi1 = bi1.divide(bi2); System.out.println(bi1); bi1 = bi1.negate(); System.out.println(bi1); int exponent = 2; bi1 = bi1.pow(exponent); System.out.println(bi1); } }