//GreatestCommonDivisor.java

public class GreatestCommonDivisor
{
    public static void main(String[] args)
    {
        System.out.println("\nTesting gcd() ...");
        System.out.println(gcd(12, 30));
        System.out.println();
        System.out.println(gcd(30, 12));
        System.out.println();
        System.out.println(gcd(12345, 54321));
        System.out.println();
        System.out.println(gcd(30, 0));
        System.out.println();
        System.out.println(gcd(0, 30));
        System.out.println();
        System.out.println(gcd(34, 187));
        System.out.println();
        System.out.println(gcd(7777, 555));
        System.out.println();
        System.out.println(gcd(97, 43));
    }

    //Computes and returns the greatest common divisor of a and b.
    //Assumes a, b >= 0 and at least one of them is > 0.
    public static int gcd
    (
        int a,
        int b
    )
    {
        //Inserted one line of "tracing code":
        System.out.println("a: " + a + "  b: " + b);
        if (b == 0)
            return a;
        else
            return gcd(b, a % b);
    }
}

