Java gcd gcd(int a, int b)

Here you can find the source of gcd(int a, int b)

Description

gcd

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Return

the greatest common divisor of a and b

Declaration

public static int gcd(int a, int b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  www  . j  a  v  a2s.  c o m
     * @param a
     * @param b
     * @return the greatest common divisor of {@code a} and {@code b}
     */
    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    /**
     * @param a
     * @param b
     * @return the greatest common divisor of {@code a} and {@code b}
     */
    public static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }
}

Related

  1. gcd(double a, double b)
  2. GCD(double a, double b)
  3. gcd(final int a, final int b)
  4. gcd(final int p, final int q)
  5. gcd(int a, int b)
  6. gcd(int a, int b)
  7. gcd(int a, int b)
  8. gcd(int a, int b)
  9. gcd(int a, int b)