Java gcd gcdMultiple(int[] nums)

Here you can find the source of gcdMultiple(int[] nums)

Description

gcd Multiple

License

Open Source License

Declaration

public static int gcdMultiple(int[] nums) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    public static int gcdMultiple(int[] nums) {
        if (nums.length == 0)
            return 0;

        Arrays.sort(nums);//w w w .j av a 2s.  c o  m
        int result = nums[0];

        for (int i = 1; i < nums.length; ++i) {
            result = gcd(result, nums[i]);
        }

        return result;
    }

    public static int gcd(int a, int b) {
        while (b != 0) {
            int h = a % b;
            a = b;
            b = h;
        }

        return a;
    }
}

Related

  1. gcd(long x, long y)
  2. gcd(long[] array)
  3. gcd(long[] array)
  4. gcd1(long given1, long given2)
  5. GCDHelper(long a, long b)
  6. gcdPositive(int a, int b)
  7. gcdPositive(int... args)
  8. gcdRec(int a, int b)
  9. gcdUsingEuclides(long x, long y)