Java Data Type Tutorial - Java BigInteger.abs()








Syntax

BigInteger.abs() has the following syntax.

public BigInteger abs()

Example

In the following code shows how to use BigInteger.abs() method.

/*from  w  w  w . j av  a2s .  c o m*/

import java.math.BigInteger;

public class Main {

  public static void main(String[] args) {

    BigInteger bi1 = new BigInteger("123");
    BigInteger bi2 = new BigInteger("-123");

    // assign absolute values of bi1, bi2 to bi3, bi4
    BigInteger bi3 = bi1.abs();
    BigInteger bi4 = bi2.abs();

    System.out.println(bi3);
    System.out.println(bi4);
  }
}

The code above generates the following result.