java - Java8 reducing a stream -


i have following methods:

static intstream streameddivisors(final int n) {     return intstream.range(2, n).parallel().filter(input -> n % input == 0); }  static int streamedphi(final int n) {     return streameddivisors(n).reduce(0, x -> x * x); } 

and i'm getting compilation error in streamedphi indicating have incompatible parameter types in lambda expression. can me make sense of this? i'm trying take divisors of given number n, , aggregate number on function defined (in case, squaring number).

your compilation issue due fact intbinaryoperator#applyasint(int, int) takes 2 arguments. declaring/providing one.

as stated in comments , after looking @ javadoc of intstream#reduce(int, intbinaryoperator) , aren't applying valid reduction. it's not clear me mean and aggregate number on function defined brian has suggestions.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -