java:BigInteger类的概述和方法使用

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_24644517/article/details/82936497

 * A:BigInteger的概述
 可以让超过Integer范围内的数据进行运算
 B:构造方法
 public BigInteger(String val)
 C:成员方法
 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)

import java.math.BigInteger;

public class Demo4_BigInteger {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String bi1="284382947912749724397293";
		BigInteger bi2=new BigInteger("100");
		BigInteger bi3=new BigInteger("2");
		System.out.println(bi2.add(bi3));//相加
		System.out.println(bi2.subtract(bi3));//相减
		System.out.println(bi2.multiply(bi3));//相乘
		System.out.println(bi2.divide(bi3));//相除
		
		BigInteger[] arr=bi2.divideAndRemainder(bi3);//两个 BigInteger 的数组:商 (this / val) 是初始元素,余数 (this % val) 是最终元素。 
		for (int i = 0; i < arr.length; i++) {
			System.out.println("数组的值:"+arr[i]);
		}
	}

}

猜你喜欢

转载自blog.csdn.net/qq_24644517/article/details/82936497