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 }

    运行效果如下:

  • 相关阅读:
    关于Socket.IO
    关于js的执行与加载
    关于XSS
    关于浏览器的渲染过程
    关于高级前端的面试题
    关于js的设计模式(简单工厂模式,构造函数模式,原型模式,混合模式,动态模式)
    关于js的高级函数(惰性函数,函数柯里化,级联函数)
    关于map
    bzoj 2744: [HEOI2012]朋友圈 二分图匹配
    bzoj 3637: Query on a tree VI 树链剖分 && AC600
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4838422.html
Copyright © 2011-2022 走看看