La classe Big Integer étend Number et implémente l’interface Comparable. Il fournit des analogues à tous les opérateurs entiers primitifs de Java et à toutes les méthodes du package java.lang.Math.
Il se compose de nombreuses méthodes ou opérations pour l'arithmétique modulaire, le GCD et bien d'autres qui sont décrites ci-dessous.
| abdos() | Il renvoie un BigInteger dont la valeur est la valeur absolue de ce BigInteger. |
| ajouter() | Cette méthode renvoie un BigInteger en calculant simplement la valeur « this + val ». |
| et() | Cette méthode renvoie un BigInteger en calculant la valeur 'this & val'. |
| et pas() | Cette méthode renvoie un BigInteger en calculant la valeur 'this & ~val'. |
| nombre de bits() | Cette méthode renvoie le nombre de bits dans la représentation en complément à deux de ce BigInteger qui diffère de son bit de signe. |
| bitLongueur() | Cette méthode renvoie le nombre de bits dans la représentation en complément à deux minimum de ce bit de signe, à l'exclusion du bit de signe. |
| clearBit() | Cette méthode renvoie un BigInteger dont la valeur est égale à ce BigInteger dont le bit désigné est effacé. |
| comparer aux() | Cette méthode compare ce BigInteger au BigInteger spécifié. |
| diviser() | Cette méthode renvoie un BigInteger en calculant la valeur 'this /~val'. |
| diviserEtRemainder() | Cette méthode renvoie un BigInteger en calculant la valeur 'this & ~val' suivie de 'this%value'. |
| doubleValeur() | Cette méthode convertit ce BigInteger en double. |
| équivaut à() | Cette méthode compare ce BigInteger avec l'objet donné pour vérifier l'égalité. |
| flipBit() | Cette méthode renvoie un BigInteger dont la valeur est égale à ce BigInteger avec le bit désigné inversé. |
| ValeurFlottant() | Cette méthode convertit ce BigInteger en float. |
| pgcd() | Cette méthode renvoie un BigInteger dont la valeur est le plus grand diviseur commun entre abs(this) et abs(val). |
| getLowestSetBit() | Cette méthode renvoie l'index du bit le plus à droite (ordre le plus bas) dans ce BigInteger (le nombre de bits zéro à droite du bit le plus à droite). |
| code de hachage() | Cette méthode renvoie le code de hachage de ce BigInteger. |
| valeurint() | Cette méthode convertit ce BigInteger en int. |
| estProbablePrime() | Cette méthode renvoie une valeur booléenne « true » si et seulement si ce BigInteger est premier, sinon pour les valeurs composites, il renvoie false. |
| valeur longue() | Cette méthode convertit ce BigInteger en un long. |
| maximum() | Cette méthode renvoie le maximum entre ce BigInteger et val. |
| min() | Cette méthode renvoie le minimum entre ce BigInteger et val. |
| contre() | Cette méthode renvoie une valeur BigInteger pour ce mod m. |
| modInverse() | Cette méthode renvoie un BigInteger dont la valeur est « ce mod inverse m ». |
| modPow() | Cette méthode renvoie un BigInteger dont la valeur est « thisexponent mod m ». |
| multiplier() | Cette méthode renvoie un BigInteger en calculant la valeur 'this *val'. |
| nier() | Cette méthode renvoie un BigInteger dont la valeur est « -this ». |
| suivantProbablePrime() | Cette méthode renvoie le prochain entier premier supérieur à ce BigInteger. |
| pas() | Cette méthode renvoie un BigInteger dont la valeur est « ~this ». |
| ou() | Cette méthode renvoie un BigInteger dont la valeur est 'this | val' |
| pow() | Cette méthode renvoie un BigInteger dont la valeur est 'thisexposant'. |
| probablePrime() | Cette méthode renvoie un BigInteger premier positif, avec le bitLength spécifié. |
| reste() | Cette méthode renvoie un BigInteger dont la valeur est « ce % val ». |
| setBit() | Cette méthode renvoie un BigInteger dont la valeur est égale à ce BigInteger avec le jeu de bits désigné. |
| décalageGauche() | Cette méthode renvoie un BigInteger dont la valeur est 'this << val'. |
| shiftRight() | Cette méthode renvoie un BigInteger dont la valeur est 'this >> val'. |
| signe() | Cette méthode renvoie la fonction signum de ce BigInteger. |
| soustraire() | Cette méthode renvoie un BigInteger dont la valeur est « this - val ». |
| bit de test() | Cette méthode renvoie une valeur booléenne « true » si le bit désigné est défini. |
| versByteArray() | Cette méthode renvoie un tableau d'octets contenant la représentation en complément à deux de ce BigInteger. |
| àChaîne() | Cette méthode renvoie la représentation sous forme décimale de ce BigInteger. |
| valeur de() | Cette méthode renvoie un BigInteger dont la valeur est équivalente à celle du long spécifié. |
| gratuit() | Cette méthode renvoie un BigInteger ny calculant la valeur 'this ^ val'. |
Exemple 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> Exemple 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); } } Testez-le maintenant Sortir:
Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272
=n>