25 大数处理--使用案例

简介: 1 大整数的处理使用BigInteger

1 大整数的处理使用BigInteger


代码示例:


public class BigNumber {
    public static void main(String[] args) {
        BigInteger bigInteger = new BigInteger("123456789123456");
        BigInteger bigInteger2 = new BigInteger("123321");
        BigInteger temp;
//            加法
        temp = bigInteger.add(bigInteger2);
        System.out.println(bigInteger+"与"+bigInteger2+"的和为:"+temp);
//        减法
        temp = bigInteger.subtract(bigInteger2);
        System.out.println(bigInteger+"与"+bigInteger2+"的差为:"+temp);
//        乘法
        temp = bigInteger.multiply(bigInteger2);
        System.out.println(bigInteger+"与"+bigInteger2+"的积为:"+temp);
//        除法
        temp = bigInteger.divide(bigInteger2);
        System.out.println(bigInteger+"与"+bigInteger2+"的商为:"+temp);
    }
}


2 大小数处理使用


代码示例:


public class BigDecimalDemo {
    public static void main(String[] args) {
        BigDecimal bd1 = new BigDecimal("15113151315131.15153151652");
        BigDecimal bd2 = new BigDecimal("5");
        BigDecimal temp;
//        加法
        temp = bd1.add(bd2);
        System.out.println("和为:"+temp);
//        减法
        temp = bd1.subtract(bd2);
        System.out.println("差为:"+temp);
//        乘法
        temp = bd1.multiply(bd2);
        System.out.println("积为:"+temp);
//        除法
        temp = bd1.divide(bd2);
        System.out.println("商为:"+temp);
    }
}


目录
相关文章
|
9月前
|
存储 C++ 容器
C++进阶--mep和set的模拟实现
C++进阶--mep和set的模拟实现
|
JSON 对象存储 数据格式
SpringMvc--综合案例
SpringMvc--综合案例
45 0
|
9月前
|
数据采集 程序员 开发工具
LabVIEW​能否​像​C​语言​一样
LabVIEW​能否​像​C​语言​一样
72 0
|
9月前
|
数据库
​小课堂 -- 报错注入(Get)
​小课堂 -- 报错注入(Get)
30 0
|
机器学习/深度学习 监控 开发工具
【MAX78000基础案例演示
【MAX78000基础案例演示
321 0
【MAX78000基础案例演示
|
前端开发
前端学习案例2-new target
前端学习案例2-new target
67 0
前端学习案例2-new target
|
前端开发
前端学习案例1-new target
前端学习案例1-new target
57 0
前端学习案例1-new target
|
C++ 容器
set以及使用举例--C++基础
set以及使用举例--C++基础
162 0
set以及使用举例--C++基础
|
存储 设计模式 Java
​如何让技术想法更容易被理解?
沟通说起来简单,要做好却很难。如何把复杂的技术问题通俗易懂地表达出来,让别人听懂,是每个技术人都会面临的难题。本文作者以自身经历为背景,总结技术人员在日常技术交流过程中,遇到的一些低效的技术沟通方式,尝试分析沟通双方的心理状态,并试图探讨提升沟通效率的方法。
​如何让技术想法更容易被理解?
|
数据库 OLAP OLTP