给定两个数字(0-9)字符串(长度不限)求它们的乘积。
输入描述:
第一行为第一个数字字符串 第二行为第二个数字字符串 输出描述:
乘积字符串
示例1
输入
123 20
输出
2460
解题思路:
直接用整数乘显然不行,这里采用math包下的BigInteger类,原理就是直接通过字符串按位乘,可进行无限位的乘法。
import java.util.*;
import java.math.BigInteger;
public class Main{
public static void main(String[] argas){
Scanner sc = new Scanner(System.in);
String n1 = sc.nextLine();
String n2 = sc.nextLine();
BigInteger c = new BigInteger(n1);
BigInteger d = new BigInteger(n2);
BigInteger e = c.multiply(d);
System.out.println(e);
}
}