8.6.2 BigInteger类
BigInteger类提供任意精度的整数运算
常用方法:
public BigInteger add(BigInteger val) //返回当前大整数对象与参数指定的大整数对象的和
public BigInteger subtract(BigInteger val) //返回当前大整数对象与参数指定的大整数对象的差
public BigInteger multiply(BigInteger val) //返回当前大整数对象与参数指定的大整数对象的积
public BigInteger divide(BigInteger val) //返回当前大整数对象与参数指定的大整数对象的商
public BigInteger remainder(BigInteger val) //返回当前大整数对象与参数指定的大整数对象的余
public BigInteger compareTo(BigInteger val) //返回当前大整数对象与参数指定的大整数的比较结果,返回值是1、-1或者0,分别表示当前大整数对象大于、小于或者等于参数指定的大整数
public BigInteger abs() //返回当前大整数对象的绝对值
public BigInteger pow(int a) //返回当前大整数对象的a次幂
public BigInteger toString() //返回当前大整数对象十进制的字符串表示
public BigInteger toString(int p) //返回当前大整数对象p进制的字符串表示
/**
* 计算5的平方根以及两个大整数的和与积
* @author night
*
*/
public class Example8_18 {
public static void main(String[] args) {
double a =5.0;
double st=Math.sqrt(a);
System.out.println(a+"的平方根:"+st);
BigInteger bigInteger=new BigInteger("0"),
one=new BigInteger("123456789"),
two=new BigInteger("987654321");
bigInteger=one.add(two);
System.out.println("和:"+bigInteger);
bigInteger=one.multiply(two);
System.out.println("积:"+bigInteger);
}
}
/*
5.0的平方根:2.23606797749979
和:1111111110
积:121932631112635269
*/