Big Integer クラスは Number を拡張し、Comparable インターフェイスを実装します。これは、Java のすべての基本整数演算子と java.lang.Math パッケージのすべてのメソッドに類似したものを提供します。
これは、モジュラー算術、GCD、および以下に説明するその他の多くのメソッドまたは演算で構成されます。
| 腹筋() | この BigInteger の絶対値を値とする BigInteger を返します。 |
| 追加() | このメソッドは、「this + val」値を計算するだけで BigInteger を返します。 |
| そして() | このメソッドは、「this & val」値を計算して BigInteger を返します。 |
| andNot() | このメソッドは、「this & ~val」値を計算して BigInteger を返します。 |
| ビットカウント() | このメソッドは、この BigInteger の 2 の補数表現で符号ビットとは異なるビット数を返します。 |
| ビット長() | このメソッドは、符号ビットを除いた、この符号ビットの最小の 2 の補数表現のビット数を返します。 |
| クリアビット() | このメソッドは、指定されたビットがクリアされたこの BigInteger と等しい値を持つ BigInteger を返します。 |
| 比較対象() | このメソッドは、この BigInteger を指定された BigInteger と比較します。 |
| 分ける() | このメソッドは、「this /~val」値を計算して BigInteger を返します。 |
| DivisionAndRemainder() | このメソッドは、「this & ~val 」値に続いて「this%value」を計算することで BigInteger を返します。 |
| doubleValue() | このメソッドは、この BigInteger を double に変換します。 |
| 等しい() | このメソッドは、この BigInteger と指定された Object が等しいかどうかを比較します。 |
| フリップビット() | このメソッドは、指定されたビットを反転したこの BigInteger と等しい値を持つ BigInteger を返します。 |
| floatValue() | このメソッドは、この BigInteger を float に変換します。 |
| gcd() | このメソッドは、abs(this) と abs(val) の間の最大公約数を値とする BigInteger を返します。 |
| getLowestSetBit() | このメソッドは、この BigInteger の右端の 1 ビット (最下位) のインデックス (右端の 1 ビットの右にある 0 ビットの数) を返します。 |
| ハッシュコード() | このメソッドは、この BigInteger のハッシュ コードを返します。 |
| intValue() | このメソッドは、この BigInteger を int に変換します。 |
| isProbablePrime() | このメソッドは、この BigInteger が素数である場合にのみ、ブール値「true」を返します。それ以外の場合、複合値の場合は false を返します。 |
| longValue() | このメソッドは、この BigInteger を Long に変換します。 |
| 最大() | このメソッドは、この BigInteger と val の間の最大値を返します。 |
| 分() | このメソッドは、この BigInteger と val の間の最小値を返します。 |
| に対して() | このメソッドは、この mod m の BigInteger 値を返します。 |
| modInverse() | このメソッドは、値が「this inverse mod m」である BigInteger を返します。 |
| modPow() | このメソッドは、値が「thisexponent mod m」である BigInteger を返します。 |
| かける() | このメソッドは、「this *val」値を計算して BigInteger を返します。 |
| 否定() | このメソッドは、値が「-this」である BigInteger を返します。 |
| nextProbablePrime() | このメソッドは、この BigInteger より大きい次の素数整数を返します。 |
| ない() | このメソッドは、値が「~this」である BigInteger を返します。 |
| または() | このメソッドは、値が「this |」である BigInteger を返します。ヴァル |
| 捕虜() | このメソッドは、値が「this」である BigInteger を返します。指数'。 |
| 確率プライム() | このメソッドは、指定された bitLength を持つ正の素数 BigInteger を返します。 |
| 残り() | このメソッドは、値が「this % val」である BigInteger を返します。 |
| setBit() | このメソッドは、指定されたビットが設定されたこの BigInteger と等しい値を持つ BigInteger を返します。 |
| シフトレフト() | このメソッドは、値が「this << val」である BigInteger を返します。 |
| シフト右() | このメソッドは、値が「this >> val」である BigInteger を返します。 |
| サイン() | このメソッドは、この BigInteger の符号関数を返します。 |
| 減算() | このメソッドは、値が「this - val」である BigInteger を返します。 |
| テストビット() | 指定されたビットが設定されている場合、このメソッドはブール値「true」を返します。 |
| toByteArray() | このメソッドは、この BigInteger の 2 の補数表現を含むバイト配列を返します。 |
| toString() | このメソッドは、この BigInteger の 10 進数の String 表現を返します。 |
| 値の() | このメソッドは、指定された long の値と等しい BigInteger を返します。 |
| 無料() | このメソッドは、「this ^ val 」値を計算して BigInteger を返します。 |
例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>