Java BigInteger類知識點總結

來源:互聯網
上載者:User

標籤:pareto   絕對值   math   inf   處理   精度   rac   異常   知識點   

(1)程式有時需要處理大整數,java.math包中的BigInteger類提供任意精度的整數運算,可以使用構造方法:

public BigInteger(String VAL)構造一個十進位的BigInteger對象,該構造方法可以發生NumberFormatException異常,也就是說,字串參數VAL中如果含有非數字字元就會發生NumberFormatException異常。

(2)BigInteger類的常用方法:

public BigInteger add(BigInteger val)   返回當前大整數對象與參數指定的大整數對象的和

public BigInteger subtract(BigInteger val)  返回當前大整數對象與參數指定的大整數對象的差

public BigInteger multiply(BigInteger val)   返回當前大整數對象與參數指定的大整數對象的積

public BigInteger devide(BigInteger val)    返回當前大整數對象與參數指定的大整數對象的商

public BigInteger remainder(BigInteger val)    返回當前大整數對象與參數指定的大整數對象的餘

public int compareTo(BigInteger val)    返回當前大整數對象與參數指定的大整數對象的比較結果,傳回值是1、-1、0,分別表示當前大整數對象大於、小於或等於參數指定的大整數。

public BigInteger abs()    返回當前大整數對象的絕對值

public BigInteger pow(int exponent)   返回當前大整數對象的exponent次冪。

public String toString()    返回當前當前大整數對象十進位的字串表示。

public String toString(int p)   返回當前大整數對象p進位的字串表示。

(3)

Java BigInteger類知識點總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.