Java gcd gcd(int k, int m)

Here you can find the source of gcd(int k, int m)

Description

gcd

License

Apache License

Declaration

public static final int gcd(int k, int m) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static final int gcd(int k, int m) {
        int larger = k;
        int smaller = m;
        if (m > k) {
            smaller = k;/*from w  w  w. ja v a  2 s . c o m*/
            larger = m;
        }

        while (true) {
            larger -= smaller;
            if (smaller == larger)
                return smaller;

            if (smaller > larger) {
                int temp = smaller;
                smaller = larger;
                larger = temp;
            }
        }
    }
}

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