I am trying to convert this function to use Java 8 new syntax. Hopefully it will reduce the number of lines and perhaps make things clearer.
public int divisorSum(int n) {
int sum = 0;
for(int i = 1; i <= n; i ++) {
if(n % i == 0) {
sum = Integer.sum(sum, i);
}
}
return sum;
}
I tried this:
IntStream.range(0, n).forEach(i -> ... )
But according to a comment on this post by Tezra apparently it is not advisable to loop using lambdas.