Класът Big Integer разширява Number и имплементира Comparable интерфейс. Той предоставя аналози на всички примитивни целочислени оператори на Java и всички методи от пакета java.lang.Math.
Състои се от много методи или операции за модулна аритметика, GCD и много други, които са описани по-долу.
| коремни мускули() | Той връща BigInteger, чиято стойност е абсолютната стойност на това BigInteger. |
| добави () | Този метод връща BigInteger чрез просто изчисляване на стойността „this + val“. |
| и() | Този метод връща BigInteger чрез изчисляване на стойността 'this & val'. |
| и не() | Този метод връща BigInteger чрез изчисляване на стойността 'this & ~val'. |
| bitCount() | Този метод връща броя на битовете в двукомплементното представяне на това BigInteger, което се различава от неговия знаков бит. |
| bitLength() | Този метод връща броя на битовете в минималното представяне на двойката на този знаков бит, с изключение на знаковия бит. |
| clearBit() | Този метод връща BigInteger, чиято стойност е равна на това BigInteger, чийто определен бит е изчистен. |
| сравни с() | Този метод сравнява това BigInteger с определеното BigInteger. |
| разделям() | Този метод връща BigInteger чрез изчисляване на стойността 'this /~val'. |
| divideAndRemainder() | Този метод връща BigInteger, като изчислява стойността 'this & ~val', последвана от 'this%value'. |
| двойна стойност () | Този метод преобразува това BigInteger в двойно. |
| равно на() | Този метод сравнява това BigInteger с дадения обект за равенство. |
| flipBit() | Този метод връща BigInteger, чиято стойност е равна на това BigInteger с указания обърнат бит. |
| floatValue() | Този метод преобразува това BigInteger в плаващо. |
| gcd() | Този метод връща BigInteger, чиято стойност е най-големият общ делител между abs(this) и abs(val). |
| getLowestSetBit() | Този метод връща индекса на най-десния един бит (най-нисък ред) в това BigInteger (броят нула битове вдясно от най-десния един бит). |
| хеш код() | Този метод връща хеш кода за този BigInteger. |
| intValue() | Този метод преобразува това BigInteger в int. |
| isProbablePrime() | Този метод връща булева стойност „true“ ако и само ако това BigInteger е просто, иначе за съставни стойности той връща false. |
| longValue() | Този метод покрива BigInteger до long. |
| макс () | Този метод връща максимума между това BigInteger и val. |
| мин() | Този метод връща минимума между това BigInteger и val. |
| срещу() | Този метод връща стойност BigInteger за този мод m. |
| modInverse() | Този метод връща BigInteger, чиято стойност е 'this inverse mod m'. |
| modPow() | Този метод връща BigInteger, чиято стойност е 'thisexponent mod m'. |
| умножение () | Този метод връща BigInteger чрез изчисляване на стойността „this *val“. |
| отрицание () | Този метод връща BigInteger, чиято стойност е '-this'. |
| nextProbablePrime() | Този метод връща следващото просто цяло число, което е по-голямо от това BigInteger. |
| не() | Този метод връща BigInteger, чиято стойност е '~this'. |
| или() | Този метод връща BigInteger, чиято стойност е 'this | Вал' |
| pow() | Този метод връща BigInteger, чиято стойност е 'thisекспонент'. |
| probablePrime() | Този метод връща положително просто BigInteger с указаната bitLength. |
| остатък() | Този метод връща BigInteger, чиято стойност е 'this % val'. |
| setBit() | Този метод връща BigInteger, чиято стойност е равна на това BigInteger с определения набор от битове. |
| shiftLeft() | Този метод връща BigInteger, чиято стойност е 'this << val'. |
| shiftRight() | Този метод връща BigInteger, чиято стойност е 'this >> val'. |
| знак() | Този метод връща функцията signum на този BigInteger. |
| изваждам() | Този метод връща BigInteger, чиято стойност е 'this - val'. |
| testbit() | Този метод връща булева стойност 'true', ако зададеният бит е зададен. |
| toByteArray() | Този метод връща масив от байтове, съдържащ допълващо представяне на това голямо цяло число. |
| toString() | Този метод връща десетичното представяне на низ на това BigInteger. |
| стойност на() | Този метод връща BigInteger, чиято стойност е еквивалентна на тази на посочения long. |
| Безплатно() | Този метод връща BigInteger ny изчислителна стойност 'this ^ val '. |
Пример 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> Пример 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); } } Тествайте сега Изход:
Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272
=n>