/Greatest Common Divisior

Greatest Common Divisior

Program for finding the greatest common divisor or Highest common factor for two numbers.

public class Gcd {

    public static void main(String args[]) {
        int gcd = gcd(2336, 1314);
        System.out.println(gcd);
    }
    
   

    private static int gcd(int a, int b) {
        int temp = a % b;
        if (temp == 0) {
            return b;
        }
        a = b;
        b = temp;
        return gcd(a, b);
    }
}