logo

Didelių sveikųjų skaičių klasė

Big Integer klasė išplečia skaičių ir įdiegia palyginamą sąsają. Jis suteikia analogų visiems Java primityviųjų sveikųjų skaičių operatoriams ir visiems metodams iš java.lang.Math paketo.

java numatytieji parametrai

Jį sudaro daugybė metodų arba operacijų, skirtų modulinei aritmetikai, GCD ir daugeliui kitų, aprašytų toliau.

abs () Jis grąžina BigInteger, kurio reikšmė yra absoliuti šio BigInteger reikšmė.
papildyti() Šis metodas grąžina BigInteger tiesiog apskaičiuodamas reikšmę „this + val“.
ir () Šis metodas grąžina BigInteger, apskaičiuodamas „this & val“ reikšmę.
ir ne() Šis metodas grąžina BigInteger, apskaičiuodamas „this & ~val“ reikšmę.
bitų skaičius () Šis metodas grąžina bitų skaičių šio BigInteger dviejų komplemento atvaizde, kuris skiriasi nuo jo ženklo bito.
bitų ilgis () Šis metodas grąžina šio ženklo bito minimalaus dviejų komplemento atvaizdavimo bitų skaičių, neįskaitant ženklo bito.
ClearBit() Šis metodas grąžina BigInteger, kurio reikšmė yra lygi šiam BigInteger, kurio nurodytas bitas išvalytas.
palyginti su() Šis metodas palygina šį BigInteger su nurodytu BigInteger.
padalinti() Šis metodas grąžina BigInteger, apskaičiuodamas „this /~val“ reikšmę.
divideAndRemainder() Šis metodas grąžina BigInteger, apskaičiuodamas reikšmę „this & ~val“, o po to „this%value“.
doubleValue() Šis metodas paverčia šį BigInteger į dvigubą.
lygus () Šis metodas lygina šį BigInteger su pateiktu objektu, kad būtų lygybė.
flipBit() Šis metodas grąžina BigInteger, kurio reikšmė yra lygi šiam BigInteger, kai nurodytas bitas yra apverstas.
floatValue() Šis metodas paverčia šį BigInteger į plūduriuojančią.
gcd () Šis metodas grąžina BigInteger, kurio reikšmė yra didžiausias bendras abs(this) ir abs(val) daliklis.
getLowestSetBit() Šis metodas grąžina dešiniojo vieno bito (žemiausios eilės) indeksą šiame BigInteger (nulio bitų skaičius dešinėje pusėje esančio bito dešinėje).
maišos kodas () Šis metodas grąžina šio BigInteger maišos kodą.
intValue() Šis metodas konvertuoja šį BigInteger į tarpinį skaičių.
isProbablePrime() Šis metodas grąžina Būlio reikšmę „true“ tada ir tik tada, kai šis BigInteger yra pirminis sudėtinių verčių skaičius, jis grąžina false.
longValue() Šis metodas ilgą laiką uždengia šį BigInteger.
max () Šis metodas grąžina maksimumą tarp šio BigInteger ir val.
min() Šis metodas grąžina minimumą tarp šio BigInteger ir val.
prieš () Šis metodas grąžina BigInteger reikšmę šiam mod m.
modInverse() Šis metodas grąžina BigInteger, kurio reikšmė yra „šis atvirkštinis mod m“.
modPow() Šis metodas grąžina BigInteger, kurio reikšmė yra „thisexpponent mod m“.
padauginti () Šis metodas grąžina BigInteger, apskaičiuodamas „this *val“ reikšmę.
paneigti () Šis metodas grąžina BigInteger, kurio reikšmė yra „-this“.
nextProbablePrime() Šis metodas grąžina kitą pirminį sveikąjį skaičių, didesnį už šį BigInteger.
ne () Šis metodas grąžina BigInteger, kurio reikšmė yra „~this“.
arba () Šis metodas grąžina BigInteger, kurio reikšmė yra „this | Val'
pow() Šis metodas grąžina BigInteger, kurio reikšmė yra „thiseksponentas“.
probablePrime() Šis metodas grąžina teigiamą pirminį BigInteger su nurodytu bitų ilgiu.
priminimas() Šis metodas grąžina BigInteger, kurio reikšmė yra „this % val“.
setBit() Šis metodas grąžina BigInteger, kurio reikšmė yra lygi šiam BigInteger su nurodytu bitų rinkiniu.
Shift Left () Šis metodas grąžina BigInteger, kurio reikšmė yra „this << val“.
ShiftRight() Šis metodas grąžina BigInteger, kurio reikšmė yra „this >> val“.
ženklas () Šis metodas grąžina šio BigInteger signum funkciją.
atimti () Šis metodas grąžina BigInteger, kurio reikšmė yra „this – val“.
testbit () Šis metodas grąžina Būlio reikšmę „true“, jei nustatytas nurodytas bitas.
toByteArray() Šis metodas grąžina baitų masyvą, kuriame yra šio BigInteger dviejų komplementų vaizdas.
toString() Šis metodas grąžina šio BigInteger dešimtainę eilutę.
vertė() Šis metodas grąžina BigInteger, kurio vertė yra lygiavertė nurodyto ilgio vertei.
Laisvas() Šis metodas grąžina BigInteger ny skaičiuojant „this ^ val“ reikšmę.

1 pavyzdys

 import java.math.BigInteger; public class BigIntegerExample1 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger(&apos;1&apos;); 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(&apos;17&apos;); //returns the signum function of this BigInteger BigInteger bigInteger2 = new BigInteger(&apos;171&apos;); System.out.println(&apos;Signum value for &apos;+bigInteger2+&apos; : &apos;+ bigInteger2.signum()); //returns the next prime integer that is greater than this BigInteger. BigInteger sub=bigInteger2.subtract(bigInteger); System.out.println(bigInteger2+&apos;-&apos;+bigInteger+&apos; : &apos;+sub); // returns the quotient after dividing two bigInteger values BigInteger quotient=bigInteger2.divide(bigInteger); System.out.print(bigInteger2+&apos; / &apos;+bigInteger+&apos; : Quotient : &apos;+quotient); //returns the remainder after dividing two bigIntger values BigInteger remainder=bigInteger.remainder(bigInteger2); System.out.println(&apos; Remaider : &apos;+remainder); //returns a BigInteger whose value is ?this &lt;&lt; val? BigInteger shiftLeft=bigInteger.shiftLeft(4); System.out.println(&apos;ShiftLeft value : &apos;+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 pavyzdys

 import java.math.BigInteger; public class BigIntegerExample2 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger(&apos;17&apos;); //returns the signum function of this BigInteger BigInteger bigInteger2 = new BigInteger(&apos;171&apos;); System.out.println(&apos;Signum value for &apos;+bigInteger2+&apos; : &apos;+ bigInteger2.signum()); //returns the next prime integer that is greater than this BigInteger. BigInteger sub=bigInteger2.subtract(bigInteger); System.out.println(bigInteger2+&apos;-&apos;+bigInteger+&apos; : &apos;+sub); // returns the quotient after dividing two bigInteger values BigInteger quotient=bigInteger2.divide(bigInteger); System.out.print(bigInteger2+&apos; / &apos;+bigInteger+&apos; : Quotient : &apos;+quotient); //returns the remainder after dividing two bigIntger values BigInteger remainder=bigInteger.remainder(bigInteger2); System.out.println(&apos; Remaider : &apos;+remainder); //returns a BigInteger whose value is ?this &lt;&lt; val? BigInteger shiftLeft=bigInteger.shiftLeft(4); System.out.println(&apos;ShiftLeft value : &apos;+shiftLeft); } } 
Išbandykite dabar

Išvestis:

 Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272