//recursive gcd /* if y divides x evenly, then gcd(x, y) = y otherwise, gcd(x, y) = gcd(y, remainder of x/y) */ import java.util.Scanner; public class eg41_GCDdemo { public static void main(String[] args) { int num1, num2; Scanner keyboard = new Scanner(System.in); System.out.print ("Enter an integer: "); num1 = keyboard.nextInt(); System.out.print ("Enter another integer: "); num2 = keyboard.nextInt(); System.out.println("The greatest common divisor of these two numbers is " + gcd(num1, num2)); } public static int gcd(int x, int y) { //help to trace the program System.out.println(x+", "+y); if (x % y == 0) return y; else return gcd(y, x % y); } }