zoukankan      html  css  js  c++  java
  • Java基础知识强化87:BigInteger类之BigInteger加减乘除法的使用

    1. BigInteger加减乘除法的使用

    1 public BigInteger add(BigInteger val):加
    2 public BigInteger subtract(BigInteger val):减
    3 public BigInteger multiply(BigInteger val):乘
    4 public BigInteger divide(BigInteger val):除
    5 public BigInteger divideAndRemainder(BigInteger val):返回 余数的数组

    2. 代码示例:

     1 package cn.itcast_02;
     2 
     3 import java.math.BigInteger;
     4 
     5 /*
     6  * public BigInteger add(BigInteger val):加
     7  * public BigInteger subtract(BigInteger val):减
     8  * public BigInteger multiply(BigInteger val):乘
     9  * public BigInteger divide(BigInteger val):除
    10  * public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
    11  */
    12 public class BigIntegerDemo {
    13     public static void main(String[] args) {
    14         BigInteger bi1 = new BigInteger("100");
    15         BigInteger bi2 = new BigInteger("50");
    16 
    17         // public BigInteger add(BigInteger val):加
    18         System.out.println("add:" + bi1.add(bi2));
    19         // public BigInteger subtract(BigInteger val):加
    20         System.out.println("subtract:" + bi1.subtract(bi2));
    21         // public BigInteger multiply(BigInteger val):加
    22         System.out.println("multiply:" + bi1.multiply(bi2));
    23         // public BigInteger divide(BigInteger val):加
    24         System.out.println("divide:" + bi1.divide(bi2));
    25 
    26         // public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
    27         BigInteger[] bis = bi1.divideAndRemainder(bi2);
    28         System.out.println("商:" + bis[0]);
    29         System.out.println("余数:" + bis[1]);
    30     }
    31 }

    运行效果如下:

  • 相关阅读:
    什么是动态链接库
    <<TCP/IP高效编程>>读书笔记
    C++ 函数
    我的vim配置
    FastReport4.6程序员手册_翻译
    DUnit研究初步
    ADO BUG之'无法为更新定位行....' 解决之道
    极限编程的集成测试工具Dunit
    总结
    项目管理检查清单项目启动
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4838422.html
Copyright © 2011-2022 走看看