Java BigInteger.gcd(BigInteger val)

Syntax

BigInteger.gcd(BigInteger val) has the following syntax.

public BigInteger gcd(BigInteger val)

Example

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


// www.  ja  v a2  s.  co m
import java.math.BigInteger;

public class Main {

  public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("18");
    BigInteger bi2 = new BigInteger("24");

    // assign gcd of bi1, bi2 to bi3
    BigInteger bi3 = bi1.gcd(bi2);

    System.out.println(bi3);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger