Java Divisor maxCommonDivisor(int m, int n)

Here you can find the source of maxCommonDivisor(int m, int n)

Description

max Common Divisor

License

Open Source License

Declaration

public static int maxCommonDivisor(int m, int n) 

Method Source Code

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

public class Main {
    public static int maxCommonDivisor(int m, int n) {
        if (m < n) { // keep the order m > n
            int temp = m;
            m = n;//from   w  w  w.java2  s  .c o  m
            n = temp;
        }
        if (m % n == 0) { // if m divide by n is 0, n is the max common divisor
            return n;
        }
        return maxCommonDivisor(n, m % n); // recurse n and the remainder of m divide n
    }
}

Related

  1. maxCommonDivisor(int num1, int num2)
  2. maxCommonDivisorCore(int num1, int num2)
  3. maxDivisibleNumber(float yourDividend, float divisor)
  4. maxLiteralLengthDivision(int n)