In Java, the BigInteger
class handles mathematical operations involving integers outside the limits of all primitive types.
The abs()
method of the BigInteger
gets the BigInteger
object.
The syntax of the abs()
method is as follows:
public BigInteger abs()
This method doesn’t take any argument.
This method returns a BigInteger
object that has the absolute value of the current BigInteger
object value.
The example below demonstrates the use of the abs()
method:
import java.math.BigInteger;class BigIntegerAbsExample {public static void main( String args[] ) {BigInteger val1 = new BigInteger("-123123");BigInteger result = val1.abs();System.out.println(result);}}
In the code above:
BigInteger
class.import java.math.BigInteger;
BigInteger
object val1
with the value -123123
.BigInteger val1 = new BigInteger("-123123");
abs()
method on the val1
object. This method call returns a BigInteger
object. The value in the returned BigInteger
object is equal to the absolute value of the val1
object, i.e., 123123
.BigInteger result = val1.abs(); //123123