1.BigInteger类概述
可以让超过Integer范围内的数据进行运算。
2.BigInteger类的构造方法
public BigInteger(String val) 将BigInteger的十进制字符串表示形式转换为BigInteger
package com;
import java.math.BigInteger;
/**
* BigInteger类
* 可以让超过Integer范围内的数据进行运算
* 构造方法
* public BigInteger(String val)
* 成员方法
* public BigInteger add(BigInteger val)
* public BigInteger subtract(BigInteger val)
* public BigInteger multiply(BigInteger val)
* public BigInteger divide(BigInteger val)
* public BigInteger[] divideAndRemainder(BigInteger val) 返回的第一个值为商 第二个值位余数
*
*
*/
public class BigIntegerDemo {
public static void main(String[] args) {
BigInteger b1 = new BigInteger("100");
BigInteger b2 = new BigInteger("200");
//public BigInteger add(BigInteger val)
System.out.println(b1.add(b2));//300
System.out.println(b1.add(b2));//300
System.out.println(b1.add(b2));//300
System.out.println(b1.add(b2));//300
//public BigInteger subtract(BigInteger val)
System.out.println(b1.subtract(b2));//-100
//public BigInteger multiply(BigInteger val)
System.out.println(b1.multiply(b2));//20000
//public BigInteger divide(BigInteger val)
System.out.println(b1.divide(b2));//0
// public BigInteger[] divideAndRemainder(BigInteger val)
BigInteger[] bis = b1.divideAndRemainder(b2);
System.out.println(bis[0]);//0
System.out.println(bis[1]);//100
}
}本文出自 “11831428” 博客,请务必保留此出处http://11841428.blog.51cto.com/11831428/1861230
原文地址:http://11841428.blog.51cto.com/11831428/1861230