Java gcd gcd(int a, int b)

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

Description

Returns the greatest common divisor between a and b.

License

Apache License

Parameter

Parameter Description
a an integer value.
b an integer value.

Return

the greatest common divisor between a and b.

Declaration

public static int gcd(int a, int b) 

Method Source Code

//package com.java2s;
/*/*w  w w.ja v  a2 s  .  c o m*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns the greatest common divisor between a and b.
     *
     * @param a
     *            an integer value.
     * @param b
     *            an integer value.
     * @return the greatest common divisor between a and b.
     */
    public static int gcd(int a, int b) {
        return (b == 0) ? a : gcd(b, a % b);
    }
}

Related

  1. gcd(final int a, final int b)
  2. gcd(final int p, final int q)
  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)