Reputation: 663
I am trying to do this by add scanner to get user inputs, but I couldn't. You help me to improve this code by adding Scanner
to get user input. I tried it but it get some error. I'm beginner to JAVA language.
import java.math.*;
public class BigIntegerMul {
public static void main(String args[]) {
BigInteger int1 = new BigInteger("131224324234234234234313");
BigInteger int2 = new BigInteger("13345663456346435648234313");
BigInteger result = int1.multiply(int2);
System.out.println(result);
}
}
Upvotes: 2
Views: 172
Reputation: 11163
To take BigInteger
using Scanner
you may use the following code snippet -
import java.math.*;
import java.util.Scanner;
public class BigIntegerMul {
public static void main(String args[]) {
//BigInteger int1 = new BigInteger("131224324234234234234313");
//BigInteger int2 = new BigInteger("13345663456346435648234313");
BigInteger int1, int2, result;
Scanner sc = new Scanner(System.in);
System.out.println("Enter first bigInteger: ");
int1 = sc.nextBigInteger();
System.out.println("Enter second bigInteger: ");
int2 = sc.nextBigInteger();
result = int1.multiply(int2);
System.out.println("Result: " +result);
}
}
Upvotes: 2