import java.math.BigInteger; public class Main { public static void main(String[] args) { BigInteger num1 = new BigInteger("12345678987654321"); long result = num1.longValue(); System.out.println("Result: " + result); } }
import java.math.BigInteger; public class Main { public static void main(String[] args) { BigInteger num1 = new BigInteger("10000000000000000000"); BigInteger num2 = new BigInteger("9999999999999999999"); BigInteger sum = num1.add(num2); long result = sum.longValue(); System.out.println("Result: " + result); } }In this example, two BigInteger objects called num1 and num2 are created with values of "10000000000000000000" and "9999999999999999999", respectively. The add() method is used to add the two BigInteger values together, and the longValue() method is used to convert the resulting BigInteger value to a long primitive type. The result is printed to the console.