greatest Common Divisor - Java java.lang

Java examples for java.lang:Math Algorithm

Description

greatest Common Divisor

Demo Code


//package com.java2s;

public class Main {
    public static int greatestCommonDivisor(int a, int b) {
        while (b != 0) {
            int temp = b;
            b = a % b;/*w w  w .  ja  va  2 s  .c o  m*/
            a = temp;
        }

        return a;
    }
}

Related Tutorials