Klasa Big Integer proširuje Number i implementira Comparable sučelje. Pruža analogije svim Java-inim primitivnim integer operatorima i svim metodama iz paketa java.lang.Math.
Sastoji se od mnogih metoda ili operacija za modularnu aritmetiku, GCD i mnoge druge koje su opisane u nastavku.
| trbušnjaci () | Vraća BigInteger čija je vrijednost apsolutna vrijednost ovog BigIntegera. |
| dodati() | Ova metoda vraća BigInteger jednostavnim izračunavanjem vrijednosti 'this + val'. |
| i() | Ova metoda vraća BigInteger izračunavanjem vrijednosti 'this & val'. |
| andNot() | Ova metoda vraća BigInteger izračunavanjem vrijednosti 'this & ~val'. |
| bitCount() | Ova metoda vraća broj bitova u komplementarnoj reprezentaciji ovog BigIntegera koji se razlikuje od bita predznaka. |
| bitLength() | Ova metoda vraća broj bitova u minimalnoj komplementarnoj reprezentaciji ovog bita predznaka isključujući bit predznaka. |
| clearBit() | Ova metoda vraća BigInteger čija je vrijednost jednaka ovom BigIntegeru čiji je naznačeni bit izbrisan. |
| usporedi s() | Ova metoda uspoređuje ovaj BigInteger s navedenim BigIntegerom. |
| podijeliti() | Ova metoda vraća BigInteger izračunavanjem vrijednosti 'this /~val'. |
| podijeliIOstatak() | Ova metoda vraća BigInteger izračunavanjem vrijednosti 'this & ~val' iza koje slijedi 'this%value'. |
| dvostrukaVrijednost() | Ova metoda pretvara ovaj BigInteger u double. |
| jednako() | Ova metoda uspoređuje ovaj BigInteger s danim objektom radi jednakosti. |
| flipBit() | Ova metoda vraća BigInteger čija je vrijednost jednaka ovom BigIntegeru s obrnutim naznačenim bitom. |
| floatValue() | Ova metoda pretvara ovaj BigInteger u float. |
| gcd() | Ova metoda vraća BigInteger čija je vrijednost najveći zajednički djelitelj između abs(this) i abs(val). |
| getLowestSetBit() | Ova metoda vraća indeks krajnjeg desnog jednog bita (najnižeg reda) u ovom BigInteger-u (broj nula bitova desno od krajnjeg desnog jednog bita). |
| hashCode() | Ova metoda vraća hash kod za ovaj BigInteger. |
| intValue() | Ova metoda pretvara ovaj BigInteger u int. |
| isProbablePrime() | Ova metoda vraća Booleovu vrijednost 'true' ako i samo ako je ovaj BigInteger prost, inače za složene vrijednosti vraća false. |
| dugaVrijednost() | Ova metoda pretvara ovaj BigInteger u long. |
| max() | Ova metoda vraća maksimum između BigInteger-a i val. |
| min() | Ova metoda vraća minimum između ovog BigIntegera i val. |
| protiv() | Ova metoda vraća vrijednost BigInteger za ovaj mod m. |
| modInverse() | Ova metoda vraća BigInteger čija je vrijednost 'this inverse mod m'. |
| modPow() | Ova metoda vraća BigInteger čija je vrijednost 'thisexponent mod m'. |
| pomnožiti() | Ova metoda vraća BigInteger izračunavanjem vrijednosti 'this *val'. |
| negirati() | Ova metoda vraća BigInteger čija je vrijednost '-this'. |
| nextProbablePrime() | Ova metoda vraća sljedeći primarni cijeli broj koji je veći od ovog BigIntegera. |
| ne() | Ova metoda vraća BigInteger čija je vrijednost '~this'. |
| ili() | Ova metoda vraća BigInteger čija je vrijednost 'this | val' |
| pow() | Ova metoda vraća BigInteger čija je vrijednost 'thiseksponent'. |
| vjerojatniPrim() | Ova metoda vraća pozitivan primarni BigInteger, s navedenom bitLength. |
| ostatak() | Ova metoda vraća BigInteger čija je vrijednost 'this % val'. |
| setBit() | Ova metoda vraća BigInteger čija je vrijednost jednaka ovom BigIntegeru s naznačenim skupom bitova. |
| pomak ulijevo() | Ova metoda vraća BigInteger čija je vrijednost 'this << val'. |
| pomak desno() | Ova metoda vraća BigInteger čija je vrijednost 'this >> val'. |
| znak() | Ova metoda vraća funkciju signum ovog BigIntegera. |
| oduzeti() | Ova metoda vraća BigInteger čija je vrijednost 'this - val'. |
| testbit() | Ova metoda vraća Booleovu vrijednost 'true' ako je naznačeni bit postavljen. |
| toByteArray() | Ova metoda vraća niz bajtova koji sadrži komplement dva za ovaj BigInteger. |
| toString() | Ova metoda vraća decimalni prikaz niza ovog VelikogIntegera. |
| vrijednost() | Ova metoda vraća BigInteger čija je vrijednost ekvivalentna onoj navedenog long. |
| besplatno() | Ova metoda vraća BigInteger ny izračunavanje vrijednosti 'this ^ val'. |
Primjer 1
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> Primjer 2
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); } } Testirajte sada Izlaz:
Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272
=n>