/** Gcd.java - Computing the greatest common divisor of two
	      integers using the Euclidean algorithm
 */

import java.io.*;

public class Gcd 
{
    /** Assuming a and b are not 0, it return
        the gcd of a and b.
     */
    public static int gcd(int a, int b) {
	int r = a % b;
        while (r != 0) {
	    a = b;
	    b = r;
	    r = a % b;
	}
	return b;
    }

    public static void main(String[] args) throws IOException {
	BufferedReader rd = new BufferedReader(
		new InputStreamReader(System.in));
	System.out.print("Enter first integer: ");
	String s1 = rd.readLine();
	int n1 = Integer.parseInt(s1);
	System.out.print("Enter second integer: ");
	String s2 = rd.readLine();
	int n2 = Integer.parseInt(s2);
	if (n1 == 0 || n2 == 0)
	    System.out.println("Sorry, both numbers must be non zero");
	else
	    System.out.println("The gcd of " + n1 
		+ " and " + n2 + " is " + gcd(n1, n2));
	System.exit(0);
    }
}
