get Proper Divisors via IntStream - Java Lambda Stream

Java examples for Lambda Stream:IntStream

Description

get Proper Divisors via IntStream

Demo Code


    //package com.java2s;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.stream.IntStream;

    public class Main {
        public static List<Integer> getProperDivisors(int number) {
   List<Integer> properDivisors = new ArrayList<>();

   IntStream.range(1, (number / 2) + 1)
         .filter(divisor -> number % divisor == 0)
         .forEach(i -> properDivisors.add(i));

   return properDivisors;
}
    }//from  www  . j  a v  a  2s  .c  om

Related Tutorials