【洛谷学习自留】p2033 A*B问题

【洛谷学习自留】p2033 A*B问题_第1张图片解题思路:

文章中提到了数据类型的选择,所以要考虑到数值越界的问题,因为a和b的最大取值范围都是50000,也就是说结果可能会大于int类型的存储空间,所以。应该考虑更大的整数类型,long类型或者BigInteger类型。

代码实现:

import java.math.BigInteger;
import java.util.Scanner;

public class p2033 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigInteger a = sc.nextBigInteger();
        BigInteger b = sc.nextBigInteger();
        BigInteger total = a.multiply(b);
        System.out.println(total);
    }
}

你可能感兴趣的:(学习)