Is there a java equivalent to C#'s .Aggregate(foo) method? -
I am trying to accept it in Java in response to this question:
But I do not know how to implement the total work.
liner when using Java 8:
public class GCD {public static zero main (string [] args) {int [] ints = {42, 21, 14, 70}; Println (gcd (ints)); } Public Fixed In GCD (Int [] ints) {return arrays.stream (ints). Reduce ((a, b) - & gt; gcd (a, b)). GetAsInt (); } Public Fixed In GCD (Int a, Int B) {Return B == 0? A: GCD (B, A% B); }} The output is "7" The total work is called lack . Optional: Lambda can also be written with a method reference. public static int GCS (Int [] ints) {return arrays.stream (ints) .reduce (GCD :: GCD) .getAsInt (); }
Comments
Post a Comment