Here you can find the source of gcd(int a, int b)
public static int gcd(int a, int b)
//package com.java2s; //License from project: Open Source License public class Main { public static int gcd(int a, int b) { while (b > 0) { int tmp = b; b = a % b;//from w w w . ja va2s . c o m a = tmp; } return a; } public static int gcd(int[] ia) { int r = ia[0]; for (int i = 1; i < ia.length; i++) { r = gcd(r, ia[i]); } return r; } }