Given the following input:
4534534534564657652349234230947234723947234234823048230957349573209483057
12324000123123
I have attempted to assign these values to BigInteger
in the following way.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger num1 = BigInteger.valueOf(sc.nextLong());
sc.nextLine();
BigInteger num2 = BigInteger.valueOf(sc.nextLong());
BigInteger additionTotal = num1.add(num2);
BigInteger multiplyTotal = num1.multiply(num2);
System.out.println(additionTotal);
System.out.println(multiplyTotal);
}
The first value is outside of the boundaries for a Long number, and so I get the following exception:
Exception in thread "main" java.util.InputMismatchException: For input string: "4534534534564657652349234230947234723947234234823048230957349573209483057"
I assumed that BigInteger expects a Long type for use with valueOf()
method (as stated here). How can I pass extremely large numbers to BigInteger?