import java.util.Scanner; public class Demo1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int z = gcd(24,36); System.out.println("GCD of 24 and 36 = " + z); int x = input.nextInt(); int y = input.nextInt(); z = gcd(x,y); System.out.println("GCD of " + x + " and " + y + " = " + z); } public static int gcd(int x, int y) { int k, min; int GCD = 1; // Best GCD so far min = (x < y) ? x : y; for ( k = 2; k <= min; k++ ) { if ( (x%k == 0) && (y%k == 0) ) GCD = k; // a better GCD } return(GCD); // Return the GCD } }