Find out greatest common divisor - Android java.lang

Android examples for java.lang:Integer

Description

Find out greatest common divisor

Demo Code


//package com.java2s;

public class Main {


    public static int gcd(int a, int b) {
        int min = a;
        int max = b;
        if (a > b) {
            min = b;/*from   w w w  .  j av  a 2  s .  c o m*/
            max = a;
        }
        if (min == 0)
            return max;
        else
            return gcd(min, max - min);
    }
}

Related Tutorials