The method
gcd(long a, long b) of Guava's
LongMath Class returns the greatest common divisor of two parameters a and b.
Syntax:
public static long gcd(long a, long b)
Parameters: This method accepts two parameters a and b of the long type of whose GCD is to be found.
Return Type: This method returns the largest positive
long value that divides both of the parameters passed to the function.
Exceptions: The method gcd(long a, long b) throws
IllegalArgumentException if a is negative or b is negative.
Note: If a and b both are zero, the method returns zero.
Example 1:
Output:
GCD of 14 and 70 is 14
GCD of 23 and 15 is 1
Example 2: