Here you can find the source of gcd(int n1, int n2)
public static int gcd(int n1, int n2)
//package com.java2s; //License from project: Open Source License public class Main { public static int gcd(int n1, int n2) { int dividend = 0; int divisor = n1 > n2 ? n1 : n2; int remainder = n1 > n2 ? n2 : n1; while (remainder > 0) { dividend = divisor;/*w w w .jav a 2 s .c o m*/ divisor = remainder; remainder = dividend % divisor; } return divisor; } }