1  import java.util.Scanner;
  2  
  3  public class GCD {
  4    /** Find gcd for integers m and n */
  5    public static int gcd(int m, int n) {
  6      int gcd = 1;
  7      
  8      if (m % n == 0) return n;
  9      
 10      for (int k = n / 2; k >= 1; k--) {
 11        if (m % k == 0 && n % k == 0) {
 12          gcd = k;
 13          break;
 14        }
 15      }
 16      
 17      return gcd;
 18    }
 19    
 20    /** Main method */
 21    public static void main(String[] args) {
 22      // Create a Scanner
 23      Scanner input = new Scanner(System.in);
 24      
 25      // Prompt the user to enter two integers
 26      System.out.print("Enter first integer: ");
 27      int m = input.nextInt();
 28      System.out.print("Enter second integer: ");
 29      int n = input.nextInt();
 30      
 31      System.out.println("The greatest common divisor for " + m +
 32        " and " + n + " is " + gcd(m, n));
 33    }
 34  }