Java gcd gcd(int n1, int n2)

Here you can find the source of gcd(int n1, int n2)

Description

gcd

License

Open Source License

Declaration

public static int gcd(int n1, int n2) 

Method Source Code

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

public class Main {
    public static int gcd(int n1, int n2) {
        int dividend = 0;
        int divisor = n1 > n2 ? n1 : n2;
        int remainder = n1 > n2 ? n2 : n1;

        while (remainder > 0) {
            dividend = divisor;/*w  w  w .jav a  2 s .c o  m*/
            divisor = remainder;
            remainder = dividend % divisor;
        }

        return divisor;
    }
}

Related

  1. gcd(int largerNumber, int smallerNumber)
  2. gcd(int m, int n)
  3. GCD(int m, int n)
  4. gcd(int m, int n)
  5. gcd(int n, int m)
  6. gcd(int num1, int num2)
  7. gcd(int p, int q)
  8. gcd(int p, int q)
  9. gcd(int u, int v)