Java中当一个数超过long类型最大值,如何处理呢?
下文笔者讲述Java中数据非常大时的处理方法分享,如下所示:
存储超大long数
实现思路:
此时我们可以使用BigInteger对超大long数进行存储及操作
例:存储超大long数
package com.java265.other;
import java.math.BigInteger;
public class test {
/*
* java265.com 超大int数存储的示例分享
*/
public static void main(String[] args) throws Exception {
BigInteger big1 = new BigInteger("8888888888888888888888888888888888888888");
BigInteger big2 = new BigInteger("88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888");
big1 = big1.add(big2);
System.out.println(big1);
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


