We know that in Mathematics, the greatest common divisor or GCD of two or more integers (provided they are not zero), is the largest positive integer that can divide each of the integers.

There might be many other positive integers that can divide the two numbers, however, the GCD will always be the largest among them. After the GCD there will not be any integer left that can divide the two integers.

You have heard of Euclidean Algorithm, that uses division method. But there are a few more, and they might look interesting to you.packagefun.sanjibsinha.gcd;public classFindGCD {

static intnumOne= 0;

static intnumTwo= 0;

static intremain= 0;

static intdivisionBased(intnum1,intnum2){

inttemp;

while(num2 != 0){

temp = num2;

num2 = num1 % num2;

num1 = temp;

}

returnnum1;

}

//this is Euclid's original versionstatic intsubtractionBased(intnum1,intnum2){

inttemp;

while(num1 != num2){

if(num1 > num2)

num1 = num1 - num2;

elsenum2 = num2 - num1;

}

returnnum1;

}

static intrecursiveBased(intnum1,intnum2){

if(num2 == 0){

returnnum1;

}else{

inttemp;

temp = num1 % num2;

returnrecursiveBased(num2, temp);

}

}

public static voidmain(String[] args)throwsArithmeticException {

System..println(outrecursiveBased(1071, 462));

//output 21}

}

` `