1 import java.util.Scanner;
2
3 public class GCD {
4
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
21 public static void main(String[] args) {
22
23 Scanner input = new Scanner(System.in);
24
25
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 }