java大數常用的方法
阿新 • • 發佈:2019-02-03
建立大數物件:
BigInteger a=new BigInteger("123");
BigInteger a=BigInteger.valueOf();
常用方法:
multiply();大數*
add();大數+divide();大數/
subtract();大數-
divideAndRemainder();返回一個數組key=0存放商值,key=1存放餘數
compareTo();比較,判斷2.00與2.0相等
equals();比較,判斷2.00與2.0不相等
gcd();最大公約數
max();
min();
pow();
mod();取餘
toString();
ZERO;常量0
valueOf();
toPlainString():返回不帶指數字段的此 BigDecimal 的字串表示形式
stripTrailingZeros():去尾零
substring():
str=str.substring(int beginIndex);擷取掉str從首字母起長度為beginIndex的字串,將剩餘字串賦值給str;
str=str.substring(int beginIndex,int endIndex);擷取str中從beginIndex開始至endIndex結束時的字串,並將其賦值給str;