BigIntegerd
使用的演示
蓝桥杯大数的操作
import java.math.BigInteger;
public class BigIntegerDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
/**
* BigInteger的使用
*/
//创建BigInteger对象
String strTen="1";//十进制数字符串表示形式
BigInteger bigInt=new BigInteger(strTen);//将BigInteger的十进制字符串表示形式转换为BigInteger。
BigInteger val = new BigInteger("2");
//加法
BigInteger add = bigInt.add(val);//返回值为this+val
//减法
BigInteger subtract = bigInt.subtract(val);//返回值为this-val
//乘法
BigInteger multiply = bigInt.multiply(val);//返回值为this*val
//除法
BigInteger divide = bigInt.divide(val);//返回值为this/val
//取余
BigInteger remainder = bigInt.remainder(val);//返回值为this%val
//输出
String string = bigInt.toString();//返回此BigInteger的十进制字符串表示形式。
//取反
BigInteger negate = bigInt.negate();//返回值为 -this
//次幂
BigInteger xor = bigInt.xor(val);//返回值为 this ^ val
//比较大小
int compareTo = bigInt.compareTo(val);//返回值 -1 0 1 分别表示this<val this=val this>val
BigInteger max = bigInt.max(val);//返回this和val中大的值
BigInteger min = bigInt.min(val);//返回this和val中小的值
}
}