Computing the GCD of a BigInteger

The GCD (greatest common divisor) of two numbers a and b is the largest positive number c such that c divides a and c divides b with no remainder. The BigInteger class has a method gcd that serves this purpose.

Main.java:

import java.math.*;
 
public class Main {
   public static void main(String args[]) {
      System.out.println(new BigInteger("12345678").gcd(new BigInteger("123456")));
      System.out.println(new BigInteger("87654321").gcd(new BigInteger("654321")));
   }
}

outputs:

6
3