我试图通过添加扫描程序来获取用户输入,但我不能。您可以通过添加Scanner
来帮助我改进此代码以获取用户输入。我尝试了但它得到了一些错误。我是JAVA语言的初学者。
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);
}
}
答案 0 :(得分:2)
要使用BigInteger
获取Scanner
,您可以使用以下代码段 -
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);
}
}