Java Guava | gcd(int a, int b) method of IntMath Class
The method gcd(int a, int b) of Guava’s IntMath class returns the greatest common divisor of a, b.
public static int gcd(int a, int b) Where a and b are integers.
Return Value : Greatest common divisor of integers a and b.
Exceptions : The method gcd(int a, int b) throws IllegalArgumentException if a < 0 or b < 0.
Example 1 :
GCD of a1 & b1 is: 4 GCD of a2 & b2 is: 1
Example 2 :
java.lang.IllegalArgumentException: a (-5) must be >= 0
Note: The method returns 0 if a == 0 && b == 0.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.