Java gcd gcd(int a, int b)

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

Description

This method finds the greatest common divisor: The largest integer or the polynomial (monomial) of highest degree that is an exact divisor or each of two or more integers or polynomials.

License

Apache License

Parameter

Parameter Description
a The first multiple.
b The second multiple.

Declaration

public static int gcd(int a, int b) 

Method Source Code

//package com.java2s;
//  Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**/*from www  .j a  va  2  s  .  com*/
     * This method finds the greatest common divisor: The largest integer or the polynomial (monomial) of highest degree
     * that is an exact divisor or each of two or more integers or polynomials.
     *
     * @param a The first multiple.
     *
     * @param b The second multiple.
     *
     * @return
     */
    public static int gcd(int a, int b) {
        int t;

        while (b != 0) {
            t = b;
            b = a % b;
            a = t;
        }

        return a;
    }
}

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)
  9. gcd(int a, int b)