Constructor:Methods:
- BigInteger (String val)
Translates the integer in the String representation of a BigInteger into a BigInteger
- String toString()
Returns the String representation of this BigInteger
- BigInteger add(BigInteger val)
Returns a BigInteger whose value is the sum of this BigInteger and val.
- BigInteger subtract(BigInteger val)
Returns a BigInteger whose value is this BigInteger - val
- BigInteger multiply(BigInteger val)
Returns a BigInteger whose value is this BigInteger times val
- BigInteger divide(BigInteger val)
Returns a BigInteger whose value is the quotient of the two integers
Examples: Integer division returns an integer.
4/2 = 2
3/7 = 0
25/3 = 8- BigInteger abs()
Returns a BigInteger whose value is the absolute value of this BigInteger
- boolean equals(Object x)
Compares this BigInteger with x for equality
- BigInteger gcd(BigInteger val)
Returns a BigInteger whose value is the greatest common divisor of this BigInteger and val
- BigInteger max( BigInteger val)
Returns the maximum of this BigInteger and val
- BigInteger min(BigInteger val)
Returns the minimum of this BigInteger and val
- BigInteger mod(BigInteger m)
Returns a BigInteger whose value is the remainder when this BigInteger is divided by m. All numbers must be positive for this method to work. Therefore you MUST take the absolute value of this BigInteger and m before you use the mod operator.
Examples:
5 mod 2 = 1
20 mod 3 = 2
1 mod 3 = 1Note: the mod operator for ints is the % sign.
Example: int rem = 5 % 2;
- BigInteger pow(int exponent)
Returns a BigInteger whose value is this BigInteger raised to the exponent power
import java.math.BigInteger;
public class BigIntegerTest {
public static void main(String[] args) {
// Your statements using the BigInteger class go here.
}
}
n1 = 100000000000000
n2 = -200000000000000
Example:
BigInteger n1 = new BigInteger("100000000000000");
Example:
System.out.println("n1 = " + n1);
Example:
BigInteger sum = n1.add(n2);
System.out.println("Sum = " + sum);
Example: To perform n1 - n2
BigInteger diff1 = n1.subtract(n2);
Example 1:
BigInteger rem1 = n1.abs().mod( n2.abs() );
OR
Example 2:
BigInteger n1Pos = n1.abs();
BigInteger n2Pos = n2.abs();
BigInteger rem1 = n1Pos.mod( n2Pos );