Here you can find the source of gcd(int m, int n)
Parameter | Description |
---|---|
m | first number |
n | second number |
static public int gcd(int m, int n)
//package com.java2s; /**/* ww w.j a v a 2 s . co m*/ * Copyright (c) 2014-2017 by the respective copyright holders. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * calculates the greatest common divisor of two numbers * * @param m * first number * @param n * second number * @return the gcd of m and n */ static public int gcd(int m, int n) { if (m % n == 0) return n; return gcd(n, m % n); } /** * calculates the greatest common divisor of n numbers * * @param numbers * an array of n numbers * @return the gcd of the n numbers */ static public int gcd(Integer[] numbers) { int n = numbers[0]; for (int m : numbers) { n = gcd(n, m); } return n; } }