A Big Integer osztály kiterjeszti a számot, és összehasonlítható felületet valósít meg. Analógokat biztosít a Java összes primitív egész operátorához és a java.lang.Math csomag összes metódusához.
Számos módszert vagy műveletet tartalmaz a moduláris aritmetikához, a GCD-hez és sok máshoz, amelyeket alább ismertetünk.
| abs() | Egy BigInteger-t ad vissza, amelynek értéke ennek a BigIntegernek az abszolút értéke. |
| add() | Ez a metódus egy BigIntegert ad vissza úgy, hogy egyszerűen kiszámítja a „this + val” értéket. |
| és() | Ez a metódus egy BigIntegert ad vissza a „this & val” érték kiszámításával. |
| és nem() | Ez a metódus egy BigIntegert ad vissza a „this & ~val” érték kiszámításával. |
| bitCount() | Ez a módszer visszaadja ennek a BigIntegernek a két komplementer reprezentációjában szereplő bitek számát, amely eltér az előjelbitétől. |
| bitLength() | Ez a módszer a bitek számát adja vissza ennek az előjelbitnek a minimum kettős komplemens reprezentációjában, kivéve az előjelbitet. |
| clearBit() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke megegyezik azzal a BigInteger számmal, amelynek a kijelölt bitje törlődik. |
| összehasonlítani() | Ez a módszer összehasonlítja ezt a BigIntegert a megadott BigInteger számmal. |
| feloszt() | Ez a metódus egy BigIntegert ad vissza a 'this /~val' érték kiszámításával. |
| divideAndRemainder() | Ez a metódus egy BigInteger számot ad vissza úgy, hogy kiszámítja a „this & ~val” értéket, amelyet a „this%value” követ. |
| doubleValue() | Ez a módszer ezt a BigIntegert duplává alakítja. |
| egyenlő () | Ez a módszer összehasonlítja ezt a BigInteger-t az adott objektummal az egyenlőség érdekében. |
| flipBit() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke megegyezik ezzel a BigInteger számmal, a kijelölt bit átfordítva. |
| floatValue() | Ez a módszer ezt a BigIntegert lebegővé alakítja. |
| gcd() | Ez a metódus egy BigInteger-t ad vissza, amelynek értéke az abs(this) és abs(val) legnagyobb közös osztója. |
| getLowestSetBit() | Ez a metódus a jobb szélső egy bit (legalacsonyabb sorrendű) indexét adja vissza ebben a BigIntegerben (a nulla bitek száma a jobb szélső bittől jobbra). |
| hash kód() | Ez a metódus a BigInteger hash kódját adja vissza. |
| intValue() | Ez a metódus ezt a BigIntegert egy int. |
| isProbablePrime() | Ez a metódus akkor és csak akkor ad vissza „true” logikai értéket, ha ez a BigInteger prímszám az összetett értékekhez, hamis értéket ad vissza. |
| longValue() | Ez a módszer hosszúra takarja ezt a BigIntegert. |
| max() | Ez a módszer a BigInteger és az érték közötti maximumot adja vissza. |
| min() | Ez a módszer a BigInteger és az érték közötti minimumot adja vissza. |
| ellen() | Ez a metódus BigInteger értéket ad vissza ehhez a mod m-hez. |
| modInverse() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke 'this inverse mod m'. |
| modPow() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke „thisexponens mod m”. |
| szorzás() | Ez a metódus egy BigInteger számot ad vissza a „this *val” érték kiszámításával. |
| tagadás() | Ez a metódus egy BigInteger-t ad vissza, amelynek értéke '-this'. |
| nextProbablePrime() | Ez a metódus a következő fő egész számot adja vissza, amely nagyobb ennél a BigIntegernél. |
| nem() | Ez a metódus egy BigInteger-t ad vissza, amelynek értéke '~this'. |
| vagy() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke 'this | Val' |
| hadifogoly() | Ez a metódus egy BigInteger-t ad vissza, amelynek értéke 'thiskitevő'. |
| probablePrime() | Ez a metódus egy pozitív elsődleges BigInteger számot ad vissza, a megadott bithosszal. |
| maradék() | Ez a metódus egy BigInteger-t ad vissza, amelynek értéke 'this % val'. |
| setBit() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke megegyezik ezzel a BigIntegerrel a kijelölt bitkészlettel. |
| shiftBal() | Ez a metódus egy BigInteger-t ad vissza, amelynek értéke 'this << val'. |
| ShiftRight() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke 'this >> val'. |
| jel() | Ez a metódus ennek a BigIntegernek az előjelfüggvényét adja vissza. |
| kivon() | Ez a metódus egy BigInteger-t ad vissza, amelynek értéke 'this - val'. |
| tesztbit() | Ez a módszer 'true' logikai értéket ad vissza, ha a kijelölt bit be van állítva. |
| toByteArray() | Ez a metódus egy bájttömböt ad vissza, amely ennek a BigIntegernek a kettős-komplementumát tartalmazza. |
| toString() | Ez a metódus ennek a BigIntegernek a decimális karakterláncát adja vissza. |
| értéke() | Ez a metódus egy BigIntegert ad vissza, amelynek értéke megegyezik a megadott long értékével. |
| ingyenes() | Ez a metódus egy BigInteger ny számítási 'this ^ val' értéket ad vissza. |
1. példa
import java.math.BigInteger; public class BigIntegerExample1 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger('1'); int n=4; for (int i = 2; i <=n 4 197 ; i++){ returns a biginteger by computing ?this *val ? value. } system.out.println('factorial of : '+biginteger); boolean value ?true? if and only this is prime biginteger2="new" biginteger('197'); system.out.println('isprobableprime method will return '+ biginteger2.isprobableprime(2)); the next integer that greater than biginteger. nextprimenumber="bigInteger2.nextProbablePrime();" system.out.println('prime number to '+nextprimenumber); minimum between val min="bigInteger.min(bigInteger2);" system.out.println('min '+min); maximum max="bigInteger.max(bigInteger2);" system.out.println('maximum '+max); < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> Factorial of 4 : 24 IsProbablePrime method will return : true Prime Number next to 197 : 199 Min value : 24 Maximum value : 197 </pre> <h2>Example 2</h2> <pre> import java.math.BigInteger; public class BigIntegerExample2 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger('17'); //returns the signum function of this BigInteger BigInteger bigInteger2 = new BigInteger('171'); System.out.println('Signum value for '+bigInteger2+' : '+ bigInteger2.signum()); //returns the next prime integer that is greater than this BigInteger. BigInteger sub=bigInteger2.subtract(bigInteger); System.out.println(bigInteger2+'-'+bigInteger+' : '+sub); // returns the quotient after dividing two bigInteger values BigInteger quotient=bigInteger2.divide(bigInteger); System.out.print(bigInteger2+' / '+bigInteger+' : Quotient : '+quotient); //returns the remainder after dividing two bigIntger values BigInteger remainder=bigInteger.remainder(bigInteger2); System.out.println(' Remaider : '+remainder); //returns a BigInteger whose value is ?this << val? BigInteger shiftLeft=bigInteger.shiftLeft(4); System.out.println('ShiftLeft value : '+shiftLeft); } } </pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272 </pre> <br></=n> 2. példa
import java.math.BigInteger; public class BigIntegerExample2 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger('17'); //returns the signum function of this BigInteger BigInteger bigInteger2 = new BigInteger('171'); System.out.println('Signum value for '+bigInteger2+' : '+ bigInteger2.signum()); //returns the next prime integer that is greater than this BigInteger. BigInteger sub=bigInteger2.subtract(bigInteger); System.out.println(bigInteger2+'-'+bigInteger+' : '+sub); // returns the quotient after dividing two bigInteger values BigInteger quotient=bigInteger2.divide(bigInteger); System.out.print(bigInteger2+' / '+bigInteger+' : Quotient : '+quotient); //returns the remainder after dividing two bigIntger values BigInteger remainder=bigInteger.remainder(bigInteger2); System.out.println(' Remaider : '+remainder); //returns a BigInteger whose value is ?this << val? BigInteger shiftLeft=bigInteger.shiftLeft(4); System.out.println('ShiftLeft value : '+shiftLeft); } } Tesztelje most Kimenet:
Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272
=n>