0
点赞
收藏
分享

微信扫一扫

问题 A: API帮助文档阅读训练---大整数类 BigInteger

西特张 2022-04-13 阅读 98
java

 通过查找API帮助文档,学习BigInteger类的功能。
 

输入

从键盘输入两个代表大整数的数串aBigInt, bBigInt,

输出

 依次打印aBigInt, bBigInt的 和,差,积,商,取模(aBigInt % bBigInt),最大公约数,

样例输入

33333333333333333333333333333333333333333333333333333333333
66666666666666666666666666666666666666666666666666666666666666

样例输出

66699999999999999999999999999999999999999999999999999999999999
-66633333333333333333333333333333333333333333333333333333333333
2222222222222222222222222222222222222222222222222222222222199977777777777777777777777777777777777777777777777777777777778
0
33333333333333333333333333333333333333333333333333333333333
3

Java.math.BigInteger的包中自带加、减、乘、除和gcd算法

详见:Java高新技术——大数操作(BigInteger、BigDecimal)_李春春_的博客-CSDN博客_biginteger

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

public class Main {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        String c = reader.next();
        String d = reader.next();
        BigInteger a = new BigInteger(c);
        BigInteger b = new BigInteger(d);
        System.out.println(a.add(b));
        System.out.println(a.subtract(b));
        System.out.println(a.multiply(b));
        System.out.println(a.divide(b));
        BigInteger e[]= a.divideAndRemainder(b);
        System.out.println(e[1]);
        System.out.println(a.gcd(b));
    }
}
举报

相关推荐

0 条评论