java常用类:BigInteger类

BigInteger类表示大整数类,封装了大整数常见的数学运算.

引入:java.math.BigInteger

声明一个BigInteger类的对象,使用字符串形式表示数字.

BigInteger bi=new BigInteger("22222222");

BigInteger类的常用运算:

加法运算 :    a.add(BigInteger b);

减法运算: a.subtract(BigInteger b);

乘法运算: a.multiple(BigInteger b);

除法运算: a.divide(BigInteger b);

模运算: a.remainder(BigInteger b);

package cn.xtnotes.u2;

import java.math.BigInteger;

public class T6_BigInteger {

	public static void main(String[] args) {
		BigInteger a=new BigInteger("66666666");
		BigInteger b=new BigInteger("22222222");
		
		System.out.println(a.add(b));  //a+b
		System.out.println(a.subtract(b));  //a-b
		System.out.println(a.multiply(b));  //a*b
		System.out.println(a.divide(b));    //  a/b
		System.out.println(a.remainder(b));  //模运算 取余
	}
}

运行结果

阅读剩余
THE END