Java gcd gcd(int firstNumber, int secondNumber)

Here you can find the source of gcd(int firstNumber, int secondNumber)

Description

gcd

License

Open Source License

Parameter

Parameter Description
firstNumber a parameter
secondNumber a parameter

Return

Greatest Common Divisor of given two integers

Declaration

public static int gcd(int firstNumber, int secondNumber) 

Method Source Code

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

public class Main {
    /**/*from   w  ww. j  a va 2  s . com*/
     * @param firstNumber
     * @param secondNumber
     * @return Greatest Common Divisor of given two integers
     */
    public static int gcd(int firstNumber, int secondNumber) {

        while (firstNumber % secondNumber != 0) {
            int temp = secondNumber;
            secondNumber = firstNumber % secondNumber;
            firstNumber = temp;
        }

        return secondNumber;
    }
}

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, int... rest)
  6. gcd(int k, int m)
  7. gcd(int largerNumber, int smallerNumber)
  8. gcd(int m, int n)
  9. GCD(int m, int n)