The Euclidian algorithm is being used in a Java function for finding the greatest common divisor. The simple function calls itself (recursion) until the greatest common divisor has been reached, at which point it is returned.
Contextual Ads
More Java Resources
Advertisement
public int GCD(int x, int y)
{
if (y == 0)
{
// When x % y is 0, we found the greatest common divisor
return x;
}
// Recursion
return GCD(y, x % y);
}