BigInteger大数字方法的解释及使用

文章目录


前言

        想起最开始学编程的样子了吗?基本数据类型中,整数类型和浮点数类型,聪明如你,一定知道,它们在运算过程中会有轻微的数据损失。在工业和商业中往往却是最致命的,哒哒哒,这时就用到了BigInteger方法了!


一、BigInteger大数字方法是什么?

           BigInteger大数字方法是可以实现,取值任意精度整数的一种方法,在运算过程中,不会有任何数据的损失。

二、怎么使用?

1.使用步骤

        第一步 导入math包

import java.math.BigInteger;

        第二步 BigInteger方法实例化

BigInteger i=new BigInteger(“99999”);
BigInteger j=BigInteger.valueOf(99999L);

        第三步 使用运算方法

常用方法解释
add(BigInteger val);加法
subtract(BigInteger val);减法
multiply(BigInteger val);乘法
divide(BigInteger val);除法
remainder(BigInteger val);取余
i.add(j);
i.subtract(j);
i.multiply(j);
i.divide(j);
i.remainder(j);

代码如下:

import java.math.BigInteger;
public class args {
		public static void main(String[] args) {
			BigInteger i=new BigInteger("99999");
			BigInteger j=BigInteger.valueOf(99999L);
			BigInteger o=i.add(j);
			System.out.println(o);
		}
	
}

2.实操展示

输出结果如下:

0283950ab09c4f08b9678e427e55d531.png


总结

        以上就是BigInteger大数字方法的使用,本文仅仅简单介绍了BigInteger方法的使用,而BigInteger提供了能使我们完整地处理数据的方法。

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵果森森

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值