BigDecimal相关总结

BigDecimal相关总结

package bigInteger;

import java.math.BigInteger;

public class Test {
    public static void main(String[] args) {
        // 构造方法
        System.out.println("=========构造方法=========");
        System.out.println(new BigInteger("12361265130"));
        System.out.println(BigInteger.valueOf(65413));
        // 16进制的32 = 50
        System.out.println(new BigInteger("32", 16));

        // 运算
        System.out.println("=========运算=========");
        BigInteger a = new BigInteger("35418415365613");
        BigInteger b = new BigInteger("35454865103546");
        System.out.println(a + " + " + b + " = " + a.add(b));
        System.out.println(a + " - " + b + " = " + a.subtract(b));
        System.out.println(a + " × " + b + " = " + a.multiply(b));
        System.out.println(b + " ÷ " + a + " = " + b.divide(a));
        System.out.println(b + " ÷ " + a + " = " + b.divideAndRemainder(a)[0] + " .... " + b.divideAndRemainder(a)[1]);
        // 取余
        System.out.println(b + "÷" + a + " 余 " + b.remainder(a));
        System.out.println(b + "÷" + a + " 余 " + b.mod(a));
        // 绝对值
        System.out.println(new BigInteger("-561456").abs());
        // 相反数
        System.out.println(new BigInteger("165").negate());
        // 最大公约数
        System.out.println(new BigInteger("36").gcd(new BigInteger("48")));
        // 幂运算
        System.out.println(new BigInteger("2").pow(10));
        // 最大值最小值
        System.out.println(a.max(b));
        System.out.println(a.min(b));
        // 判断相等
        System.out.println(a.equals(a));
        System.out.println(a.equals(b));
        System.out.println(new BigInteger("1").equals(new BigInteger("1")));
        System.out.println(new BigInteger("18963").equals(new BigInteger("18963")));
        // 比较大小
        System.out.println(a.compareTo(b));
        // hash值
        System.out.println("73246598的hash值" + new BigInteger("73246598").hashCode());

        // 基本常量
        System.out.println("=========基本常量=========");
        System.out.println("BigInteger.ZERO = " + BigInteger.ZERO);
        System.out.println("BigInteger.ONE = " + BigInteger.ONE);
        System.out.println("BigInteger.TEN = " + BigInteger.TEN);
    }
}

控制台输出

=========构造方法=========
12361265130
65413
50
=========运算=========
35418415365613 + 35454865103546 = 70873280469159
35418415365613 - 35454865103546 = -36449737933
35418415365613 × 35454865103546 = 1255755138969169794692763698
35454865103546 ÷ 35418415365613 = 1
35454865103546 ÷ 35418415365613 = 1 .... 36449737933
35454865103546÷3541841536561336449737933
35454865103546÷3541841536561336449737933
561456
-165
12
1024
35454865103546
35418415365613
true
false
true
true
-1
73246598的hash值73246598
=========基本常量=========
BigInteger.ZERO = 0
BigInteger.ONE = 1
BigInteger.TEN = 10

Process finished with exit code 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值