/* File: GCD.java - March 2011 */ package l06; /** * Compute and display the gcd of the input arguments * using a recursive algorithm * * Sample usage: java l06.GCD 24 30 * * @author Michael Albert * */ public class GCD{ static int calls = 0; public static void main(String[] args) { long a = Long.parseLong(args[0]); long b = Long.parseLong(args[1]); System.out.println("GCD(" + a + ", " + b + ") = " + gcd(a,b)); System.out.println("Calls required: " + calls); } public static long gcd(long a, long b) { calls++; if (a == 0) return b; return gcd(b % a, a); } }