Returns the greatest common divisor of the specified value - Java java.lang

Java examples for java.lang:Math Value

Description

Returns the greatest common divisor of the specified value

Demo Code



public class Main{
    /**/* w  ww . ja v  a 2 s .  c  o m*/
     * Returns the greatest common divisor of the specified value
     * @param a
     * @param b
     * @return
     */
    public static int euclidDivision(int a, int b) {
        if (m == 0 || m < n)
            throw new IllegalArgumentException();
        if (n == 0)
            return m;
        int remain = m % n;
        if (remain == 0)
            return n;
        return euclidDivision(n, remain);
    }
}

Related Tutorials