Here you can find the source of gcd(int a, int b)
public static int gcd(int a, int b)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007 Australian Nuclear Science and Technology Organisation. * 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 * * Contributors://from w w w . j a v a 2s . c om * Lindsay Winkler (Bragg Institute) - initial implementation *******************************************************************************/ public class Main { /** * Find the greatest common divisor of two integers. This is done using * the Euclidean Algorithm. */ public static int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } }