欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用BigInteger實現(xiàn)除法取余

 更新時間:2021年08月13日 14:34:49   作者:昂蒂梵德  
這篇文章主要介紹了使用BigInteger實現(xiàn)除法取余操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

BigInteger 除法取余

1、BigInteger是什么?

Java中,整形的最大范圍是64位的long型整數(shù)。但是如果我們使用的整數(shù)超過了64位呢?這時候就用到了BigInteger。BigInteger內(nèi)部使用int[]數(shù)組來存儲足夠大的整數(shù)。

2、BigInteger實現(xiàn)除法取余

public class BigIntTest {
    public static void main(String[] args) {
        BigInteger bigInteger = new BigInteger("45615146541561");
        BigInteger bigInteger2 = new BigInteger("6541315");
        BigInteger[] resBigIntegers = bigInteger.divideAndRemainder(bigInteger2);
        System.out.println("兩數(shù)相除,整除結果為:" + resBigIntegers[0]  +
                           ",余數(shù)為:" + resBigIntegers[1]);
    }
}

運行結果:

file

BigInteger簡單使用及方法總結

BigInteger 可以用來解決數(shù)據(jù)的溢出問題!

下面我總結幾種關于BigInteger的常用用法:

1、probablePrime和nextprobablePrime。(判斷質(zhì)數(shù),并返回)

BigInteger.probablePrime(int x);

返回有可能是素數(shù)(質(zhì)數(shù)),具有指定長度的正數(shù)BigInteger,返回可能是合數(shù)的概率不超過2的負100次方, 

BigInteger.nextprobablePrime(int x)

返回大于此BigInteger的有可能是素數(shù)(質(zhì)數(shù)),具有指定長度的正數(shù)BigInteger,返回可能是合數(shù)的概率不超過2的負100次方

2、valueOf()(對數(shù)據(jù)初始化)

BigInteger valueOf(long val)

用法如下:

3、四則運算

(add(加)。subtract(減)。multiply(乘)。divide(除))

調(diào)用方式如上圖,可以重復調(diào)用

4、remainder(取余)

返回其值為取余后的BigInteger類型的值,例子如下

調(diào)用的時候要保證數(shù)據(jù)是BigInteger類型的,可以用初始化(valueOf)或者new一個。

5、divideAndRemainder(先除后取余,結果分別存在數(shù)組中)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論