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) { if (a > b) { int tmp = a; a = b;//from w ww . j a va 2s. c o m b = tmp; } if (a == 0) { return 0; } if (b % a == 0) { return a; } return gcd(b % a, a); } public static long gcd(long a, long b) { if (a > b) { long tmp = a; a = b; b = tmp; } if (a == 0) { return 0; } if (b % a == 0) { return a; } return gcd(b % a, a); } }