Java gcd gcd(int a, int b)

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

Description

Find the greatest common divisor of two integers.

License

Open Source License

Declaration

public static int gcd(int a, int b) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Australian Nuclear Science and Technology Organisation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w  w w . j  a v  a  2s .  c  om
 *     Lindsay Winkler (Bragg Institute) - initial implementation
 *******************************************************************************/

public class Main {
    /**
     * Find the greatest common divisor of two integers. This is done using 
     * the Euclidean Algorithm.
     */
    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }
}

Related

  1. gcd(int a, int b)
  2. gcd(int a, int b)
  3. gcd(int a, int b)
  4. gcd(int a, int b)
  5. gcd(int a, int b)
  6. gcd(int a, int b)
  7. gcd(int a, int b)
  8. gcd(int a, int b, int... rest)
  9. gcd(int firstNumber, int secondNumber)