Here you can find the source of gcd(IntStream numbers)
Parameter | Description |
---|---|
numbers | a int stream with some numbers |
public static int gcd(IntStream numbers)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.stream.IntStream; public class Main { private static int gcd(int x, int y) { return (y == 0) ? x : gcd(y, x % y); }// w ww . j ava 2s.c om /** * Calculate the greatest commom divisor of all numbers in the int stream * * @param numbers * a int stream with some numbers * @return the greatest common divisor of the numbers in the int stream */ public static int gcd(IntStream numbers) { return numbers.reduce(0, (x, y) -> gcd(x, y)); } /** * Calculate the greatest commom divisor of some integers * * @param numbers * as many integers as you like * @return the greatest common divisor of the given numbers */ public static int gcd(int... numbers) { return gcd(Arrays.stream(numbers)); } }