java

calcular GCD de dos números recursivo

public class App {

    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } // if 
        else {
            return gcd(b, a % b);
        } // else
    } // metodo gcd

    public static void main(String[] args) {

        int a = 12;
        int b = 4;

        System.out.println("El maximo comun multiplo de " + a + " y " + b + " es " + gcd(a, b));

    } // main

}
Was this helpful?