我试图通过添加扫描仪来获取用户输入来做到这一点,但我做不到。您通过添加 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);
}
}
最佳答案
要使用 Scanner
获取 BigInteger
,您可以使用以下代码片段 -
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);
}
}
关于java - JAVA中的大数相乘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30546650/